Sending SMTP Mail With Authentication with ASP.Net

by demtron on Monday, March 02, 2009 05:14 PM

Many web hosting now require sender authentication when sending e-mail through a relay server.  These mail servers have their security locked down.  Sometimes, localhost is an available SMTP server option, but if a relay server is required, a little extra code is also required.

ASP.Net offers the NetworkCredential class for this purposes.  By setting the NetworkCredential property in the SMTPClient object with the appropriate credentials, authentication can be passed with the request.  For example:

Dim smtp As New Net.Mail.SmtpClient
Dim m As New Net.Mail.MailMessage
m.Subject = "the subject"
m.From = New Net.Mail.MailAddress("email@domainname.com")
m.To.Add("john@demtron.com")
Dim Auth As New System.Net.NetworkCredential("email@domainname.com", "password")
smtp.UseDefaultCredentials = False
smtp.Credentials = Auth
smtp.Host = "smtp.domainname.com"
smtp.Send(m) 

Comments

Comments are closed

Powered by BlogEngine.NET 1.5.1.18
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share

Calendar

<<  November 2024  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer



Marketing / SEO

Blog Directory
blogarama - the blog directory
TopOfBlogs
Milwaukee area SEO, SEM, ASP.Net