AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=867&pId=-1
Sending SMTP Authenticated E-mail Using ASP.NET 2.0
page
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 156705/ 94

 

I wrote an article in May 2005 on how to send e-mail via ASP.NET v2.0.  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 e-mail from their servers.  If you have code that uses "localhost" (the SMTP service running on the local machine) then this should not be an issue, but if you have a situation where you need to relay e-mail 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 is not clear, but that is what is required.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Auth supporting e-mail 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 onthis 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.


Product Spotlight
Product Spotlight 

©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-02-27 7:50:29 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search