Sending emails in .NET#

As a follow-up to my recent post which showed how to send an email in .NET, there are some circumtances where you would need to use SMTP authentication. In fact, my guess is that this is the norm. So: here’s how you would do that:

System.Web.Mail.MailMessage em = new MailMessage() ;

string UserName = “joe@joeblogs.com ;
string Password = “******” ;

em.Body = “This is the body of the email” ;
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName); //set your username here
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord); //set your password here

// blogged with BlogJet

11/23/2005 12:11:09 AM (GMT Standard Time, UTC+00:00) #     |  Trackback

 

All content © 2012, Paul Duggan
On this page
This site
Calendar
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.8.5223.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: