Digital Colony!

Sending Email in ASP.NET Using SMTP Authentication (VB.NET)

If you don't need to use Authentication to send email, check out the code snippet Sending Email in ASP.NET 2.0 (VB.NET). If your web host requires that you use SMTP Authentication, some additional lines of code will need to be added.
Dim Message As MailMessage = New MailMessage()
Dim Smtp As New SmtpClient()
Dim SmtpUser As New System.Net.NetworkCredential()
'-- Build Message
Message.From = New MailAddress("larryking@cnn.com", "Larry King")
Message.To.Add(New MailAddress("oprah@oprah.com", "Oprah"))
Message.IsBodyHtml = False
Message.Subject = "Come on My Show Soon"
Message.Body = "Please be a guest on my show. - Larry"
'-- Define Authenticated User
SmtpUser.UserName = "larryking"
SmtpUser.Password = "suspenders"
SmtpUser.Domain = "mail.cnn.com"
'-- Send Message
Smtp.UseDefaultCredentials = False
Smtp.Credentials = SmtpUser
Smtp.Host = "mail.cnn.com"
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network
Smtp.Send(Message)

Labels: ,

AddThis Social Bookmark Button

2 Comments:

Blogger jide said...

u saved me a lot of stress.tanx man

1/30/2008 5:26 AM

Anonymous Anonymous said...

Sweet!!! U'r a savior, dogg...

4/22/2008 4:05 PM

 

Post a Comment

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.