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) #    Comments [0]  |  Trackback

 

All content © 2008, Paul Duggan
On this page
This site
Calendar
<December 2008>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
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: