Santry Technology Solutions, Content Management, DotNetNuke, SharePoint Consulting
Register | Login
Tuesday, December 02, 2008

Sections
  
About Us
  
Partners
Downloads
  
 WWWCoder.com Resource Directory

Sending SMTP-Authenticated Email From ASP.Net
9/8/2005 11:33:27 AM

Many web hosts now have their servers "locked down" and require a username and password to send email from their servers. If you have code that uses "localhost" (the SMTP service running on the local machine) then this shouldn't be an issue...

By Brad Kingsley

I wrote an article in May 2005 on how to send email via ASP.Net v2.0 http://www.wwwcoder.com/main/parentid/435/site/5103/68/default.aspx. This is a quick follow-up to that article with additional information specifically addressing the issue of SMTP-Authentication against a remote mail server.

Many web hosts now have their servers "locked down" and require a username and password to send email from their servers. If you have code that uses "localhost" (the SMTP service running on the local machine) then this shouldn't be an issue, but if you have a situation where you need to relay email off a remote mail server that is secured, this article should help you.

The real work is done by the NetworkCredential object. According to MSDN this object "provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication". The benefit of making this a two-step process rather than passing username and password to the .Credentials property of the SmtpClient object isn't clear, but that is what's required.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Auth supporting email code.


'Create a new MailMessage object and specify the "From" and "To" addresses
Dim Email As New System.Net.Mail.MailMessage("Brad.Kingsley@orcsweb.com", 
"Brad@KingsleyTeam.com") Email.Subject = "test subject" Email.Body = "this is a test" Dim mailClient As New System.Net.Mail.SmtpClient() 'This object stores the authentication values Dim basicAuthenticationInfo As New System.Net.NetworkCredential("username", "password") 'Put your own, or your ISPs, mail server name on this next line mailClient.Host = "Mail.RemoteMailServer.com" mailClient.UseDefaultCredentials = False mailClient.Credentials = basicAuthenticationInfo mailClient.Send(Email)

I would like to thank Marcus McConnell of BV Software and also Brian Linden from CastAds Inc for their tips on how to integrate the SMTP-Authentication process.

Happy coding!

~Brad

Brad Kingsley is founder and president of ORCS Web, Inc. - a company that provides managed complex hosting for clients who develop and deploy their applications on Microsoft Windows platforms.


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 7/1/2008 12:13:12 PM by Anonymous
Comments:
Left on 2/16/2006 2:50:28 PM by Anonymous
Comments: Thanks a lot, just what I needed, because it's not so obivious.
No ratings available.
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970