Send email issue

  • Hi,

    I have written a script to send email. It is not giving any error but giving the message that unable to send email. Following is the code:

    Public Sub MailSend(ByVal ToMail As String, ByVal FromMail As String, ByVal Subject As String, ByVal Message As String)

    Dim smtpclient As New SmtpClient

    Dim mailmessage As New MailMessage

    Dim fromadd As New MailAddress("Rad.Nayan@company.com")

    smtpclient.Host = Dts.Variables("SmtpServer").Value.ToString

    smtpclient.Port = 25

    smtpclient.UseDefaultCredentials = True

    mailmessage.From = fromadd

    mailmessage.To.Add("Rad.Nayan@company.com")

    mailmessage.Subject = Subject

    mailmessage.Body = Message

    smtpclient.Send(mailmessage)

    End Sub

    Please help me to find out the issue.

    Thanks

  • is there a message from the mail server itself? unable to relay, mailbox full, etc?

    that's probably where the error is, my server requires a username and password to authenticate via the AUTH command.

    heres a partial example:

    Dim strFrom As String = "lowell@somedomain.com"

    Dim strTo As String = "lowell@anotherdomain.net"

    Dim strSubject As String = "Emailed Reports"

    Dim strSMTPServer As String = "mail.mymailserver.com"

    Dim strSMTPUser = "mymailbox@somedomain.com"

    Dim strSMTPPass = "NotMyRealEmailPassword"

    Dim message As New System.Net.Mail.MailMessage(strFrom, strTo)

    message.Subject = strSubject

    message.Body = htmlBody

    message.IsBodyHtml = True

    message.Attachments.Add(New System.Net.Mail.Attachment("c:\Data\fedora_spinner.gif"))

    Dim emailClient As New System.Net.Mail.SmtpClient(strSMTPServer)

    Dim SMTPUserInfo As New System.Net.NetworkCredential(strSMTPUser, strSMTPPass)

    emailClient.UseDefaultCredentials = False

    emailClient.Credentials = SMTPUserInfo

    Try

    emailClient.Send(message)

    Catch ex As Exception

    MsgBox(ex.Message)

    End Try

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you so much for your reply. It seems I missed lot of data. Let me add all and try again.

    Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply