65.9K
CodeProject is changing. Read more.
Home

Sending Authenticated e-mail in ASP.NET 2.0

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.47/5 (10 votes)

Feb 6, 2006

viewsIcon

64584

How to send authenticated e-mail from ASP.NET (login/password)

Login to an SMTP server and send an email

There are many articles on how to send authenticated email in ASP.NET 2.0, but here's how to send an email using a SMTP server that requires authentication.

(Imports System.Net)

Dim client As New SmtpClient("smtp.server.com") 'your SMTP server
client.UseDefaultCredentials = False

'Your username and password to login
client.Credentials = New Net.NetworkCredential("username", "password") 
client.DeliveryMethod = SmtpDeliveryMethod.Network
Dim Mail As New MailMessage("from@email.com", "to@email.com", _
        "This is my subject", _
        "This is my pretty, yet boring and useless message")
Mail.IsBodyHtml = True

Try
    client.Send(Mail)
Catch ex As Exception
    Response.Write(ex.Message) 'Write error message
    Exit Sub
End Try

'successful