Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET
Article

Sending Authenticated e-mail in ASP.NET 2.0

Rate me:
Please Sign up or sign in to vote.
1.47/5 (13 votes)
5 Feb 2006 64K   35   7
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.

VB.NET
(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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
I am a software programmer from Bucharest, Romania.
I am 24 years old and I am very pleased with my job at Elven Soft, a company specialized in custom software development and web design

Comments and Discussions

 
Questionhow to mange SmtpPermission or security policy Pin
seedawi10-Sep-08 13:41
seedawi10-Sep-08 13:41 
Generalpls help Pin
wasif_Muhammad22-Feb-07 2:19
wasif_Muhammad22-Feb-07 2:19 
GeneralSending Authenticated e-mails in ASP.NET 2.0 by Using Pin
AmirK116-Jul-06 19:08
AmirK116-Jul-06 19:08 
GeneralRe: Sending Authenticated e-mails in ASP.NET 2.0 by Using Pin
svkoli1-Jan-07 15:21
svkoli1-Jan-07 15:21 
QuestionASP.Net 1.1 Pin
kokowawa67813-Mar-06 23:54
kokowawa67813-Mar-06 23:54 
AnswerRe: ASP.Net 1.1 Pin
Catalin Radoi14-Mar-06 1:28
Catalin Radoi14-Mar-06 1:28 
GeneralExchange Server Pin
Azel Low6-Feb-06 20:41
Azel Low6-Feb-06 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.