Results 1 to 2 of 2

Thread: Send email thru ASP.NET with SMTP Auth

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Send email thru ASP.NET with SMTP Auth

    Dear Expert,

    I wrote below codes for sending email using ASP.NET.. but my SMTP server requires authentication, please help ..

    Imports System.Net.Mail

    ...
    ...
    ...

    Try

    Dim SendFrom As MailAddress = New MailAddress(mFromAddr)
    Dim SendTo As MailAddress = New MailAddress(pTo)
    Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

    MyMessage.Subject = pSubject
    MyMessage.Body = pBody & vbCrLf & NoReply_Note

    Dim mAttachment As String = ""
    Dim attachFile As New Attachment(pAttachment)
    MyMessage.Attachments.Add(attachFile)

    Dim emailClient As New SmtpClient(mSMTP)

    emailClient.Send(MyMessage)

    ...
    ...

    Catch ex As Exception

    ...

    End Try

    Thanks & Regards
    Winanjaya

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: Send email thru ASP.NET with SMTP Auth

    VB Code:
    1. Dim oEmail as New Net.Mail.MailMessage()
    2.  
    3. Dim oSmtp as New Net.Mail.SmtpClient
    4. oSmtp.Host = "mail.test.com"
    5.  
    6. 'This object stores the authentication values
    7. Dim basicAuthenticationInfo As New System.Net.NetworkCredential()
    8. basicAuthenticationInfo.UserName = "username"
    9. basicAuthenticationInfo.Password = "password"
    10. oSmtp.UseDefaultCredentials = False
    11. oSmtp.Credentials = basicAuthenticationInfo
    12.  
    13. oEmail.From = New Net.Mail.MailAddress("[email protected]")
    14. oEmail.To.Add("[email protected]")
    15. oEmail.Subject = "mailSubject"
    16. oEmail.Body = "mailBody"
    17. 'send the eMail
    18. oSmtp.Send(oEmail)

    HTH
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width