System.Web.Mail FAQ

Complete FAQ Listing


3.8 How do I authenticate to send an email? Printer Friendly   Email This FAQ   Discuss

If you are using the .NET Framework 1.0, this cannot be done. However, in the 1.1 version, the MailMessage.Fields property was added. This allowed access to the underlying CDO.Message fields.

The following example demonstrates sending your username and password to the SMTP server to provide authentication.
 
[ C# ]
private void Page_Load(object sender, System.EventArgs e)
{
	MailMessage mail = new MailMessage();
	mail.To = "me@mycompany.com";
	mail.From = "you@yourcompany.com";
	mail.Subject = "this is a test email.";
	mail.Body = "Some text goes here";
	mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");	//basic authentication
	mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
	mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret");	//set your password here

	SmtpMail.SmtpServer = "mail.mycompany.com";  //your real server goes here
	SmtpMail.Send( mail );
}



[ VB.NET ]
Private Sub Page_Load(sender As Object, e As System.EventArgs)
   Dim mail As New MailMessage()
   mail.To = "me@mycompany.com"
   mail.From = "you@yourcompany.com"
   mail.Subject = "this is a test email."
   mail.Body = "Some text goes here"
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here
   SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here
   SmtpMail.Send(mail)
End Sub 'Page_Load

 

Discuss This FAQ Item
Got a question? Another Suggestion? Want to post your solution? Discuss it below.
New Post
  • System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
    • RE: System.Web.Mail & ESMTP    [ Reply ]
  • proxy information    [ Reply ]
    • RE: proxy information    [ Reply ]
      • RE RE: proxy information    [ Reply ]
        • RE: RE RE: proxy information    [ Reply ]
  • smtpauthenticate    [ Reply ]
    • RE: smtpauthenticate    [ Reply ]
      • RE RE: smtpauthenticate    [ Reply ]
        • RE: RE RE: smtpauthenticate    [ Reply ]
          • RE RE: RE RE: smtpauthenticate    [ Reply ]
          • RE RE: RE RE: smtpauthenticate    [ Reply ]
      • RE RE: smtpauthenticate    [ Reply ]
  • webmail authentification    [ Reply ]
    • RE: webmail authentification    [ Reply ]
    • RE: webmail authentification    [ Reply ]
    • RE: webmail authentification    [ Reply ]
      • RE RE: webmail authentification    [ Reply ]
  • CDO question    [ Reply ]
    • RE: CDO question    [ Reply ]
  • test    [ Reply ]
  • CDO troubles?    [ Reply ]
  • Authentication    [ Reply ]
  • About the authentication    [ Reply ]
    • RE: About the authentication    [ Reply ]
    • RE: About the authentication    [ Reply ]
  • Still can't connect    [ Reply ]
    • RE: Still can't connect    [ Reply ]
      • RE RE: Still can't connect    [ Reply ]
    • RE: Still can't connect    [ Reply ]
  • Framework1.0-send mail authentication    [ Reply ]
    • RE: Framework1.0-send mail authentication    [ Reply ]
      • RE RE: Framework1.0-send mail authentication    [ Reply ]
      • RE RE: Framework1.0-send mail authentication    [ Reply ]
  • Looks Great! But I are carfused...    [ Reply ]
    • RE: Looks Great! But I are carfused...    [ Reply ]
  • about the Mail Authentication Schemas...    [ Reply ]
  • SMTP Servers    [ Reply ]
    • RE: SMTP Servers    [ Reply ]
    • RE: SMTP Servers    [ Reply ]
    • RE: SMTP Servers    [ Reply ]
  • Attachment problem    [ Reply ]
  • 'Fields' is not a member of 'System.Web.Mail.MailMessage'    [ Reply ]
  • smtp server authentication    [ Reply ]
    • RE: smtp server authentication    [ Reply ]
      • RE RE: smtp server authentication    [ Reply ]
        • RE: RE RE: smtp server authentication    [ Reply ]
          • RE RE: RE RE: smtp server authentication    [ Reply ]
  • help!    [ Reply ]
    • RE: help!    [ Reply ]
    • RE: help!    [ Reply ]
  • is authentication necessary??    [ Reply ]
    • RE: is authentication necessary??    [ Reply ]
  • Send Email using GroupWise    [ Reply ]
  • who tell me why i still can't send a mail    [ Reply ]
  • SMTP    [ Reply ]
  • Authentication Problems    [ Reply ]
    • RE: Authentication Problems    [ Reply ]
      • RE RE: Authentication Problems    [ Reply ]
  • Smtp authentication    [ Reply ]
  • authentication SMTP    [ Reply ]
  • overwrite the default return-path field    [ Reply ]
  • The system indicates the error: can't access CDO.Message    [ Reply ]
  • How do I validate email address?    [ Reply ]
  • Can't open .aspx or User Controls after pointing project path to 1.1    [ Reply ]
  • Fields.Add Not Working in 1.1    [ Reply ]
    • RE: Fields.Add Not Working in 1.1    [ Reply ]
  • help needed    [ Reply ]
  • im confused    [ Reply ]
  • How do I pass Windows Credentials    [ Reply ]
    • RE: How do I pass Windows Credentials    [ Reply ]
  • Urgent! the athentication can't work today!!!!    [ Reply ]
  • Server not accepting authentification    [ Reply ]
    • RE: Server not accepting authentification    [ Reply ]
    • RE: Server not accepting authentification    [ Reply ]
  • Transport error    [ Reply ]
    • RE: Transport error    [ Reply ]
      • RE RE: Transport error    [ Reply ]
  • it works for me...    [ Reply ]
  • 'string' does not containt a definition for 'Fields'    [ Reply ]
  • Send Failure    [ Reply ]
  • How to hide the SMTP authentication    [ Reply ]
    • RE: How to hide the SMTP authentication    [ Reply ]
  • SMTP Authentication via ASP.NET    [ Reply ]
  • SMTP server name    [ Reply ]
    • RE: SMTP server name    [ Reply ]
    • RE: SMTP server name    [ Reply ]
  • authentication error    [ Reply ]
  • how to recieve email from hotmail,yahoo,etc mail servers in asp.net?    [ Reply ]
  • Console App Unable to Authenticate to Smtp Servers    [ Reply ]
    • RE: Console App Unable to Authenticate to Smtp Servers    [ Reply ]
  • mail.Fields.add    [ Reply ]
    • RE: mail.Fields.add    [ Reply ]
  • How to send mail using VB.NET    [ Reply ]
  • change smtp server's default port    [ Reply ]
  • username/pwd being ignored in Basic authentication    [ Reply ]
  • No error, but still no mail    [ Reply ]
  • gmail authentication methods help    [ Reply ]
  • authenticate to send an email: parameter clarification    [ Reply ]
  • Good CDO Info?    [ Reply ]
  • Error in when sending through my web site    [ Reply ]
  • CDO    [ Reply ]
  • NTLM authentication failing    [ Reply ]
  • About mail body length    [ Reply ]
  • HEEEELLLLPP!! smtp authentication does not work    [ Reply ]
  • A new Authentication problem :(    [ Reply ]
  • I Don't know why it Occours    [ Reply ]
  • Can't send E-mails outside my mail server    [ Reply ]
  • Keep getting a CDO error    [ Reply ]
  • could not Access 'CDO.Message' object    [ Reply ]
  • How to send and Email    [ Reply ]
  • Another method (NetworkCredential)    [ Reply ]
  • How do I authenticate to send an email?    [ Reply ]
    • RE: How do I authenticate to send an email?    [ Reply ]
  • The server response was: 503 This mail server requires authentication. Please check your mail client settings.    [ Reply ]
  • fixed! - Check to see that your port 25 is not blocked    [ Reply ]
  • authenticate VS 2005    [ Reply ]
    • RE: authenticate VS 2005    [ Reply ]
      • RE RE: authenticate VS 2005    [ Reply ]
  • Using SPA To Authenticate Mail    [ Reply ]
    • RE: Using SPA To Authenticate Mail    [ Reply ]
  • Basic Authentication-Exchange Server-Rejects User    [ Reply ]
  • sending mail    [ Reply ]
  • How do I authenticate using SSL?    [ Reply ]
  • want quik answer    [ Reply ]
    • RE: want quik answer    [ Reply ]
  • what worked for me    [ Reply ]
  • Queueing Problem in Sending Mail    [ Reply ]
  • The transport failed to connect to the server    [ Reply ]
  • does not contain definition for 'Fields'    [ Reply ]
    • RE: does not contain definition for 'Fields'    [ Reply ]
  • Can somebody help ??    [ Reply ]
  • CDO error in sending mail    [ Reply ]
  • problem with rediff and hotmail    [ Reply ]
  • Send email to different contacts c#    [ Reply ]
  • sent mail    [ Reply ]
  • 503 This mail server requires authentication    [ Reply ]
  • how to start smtpserver    [ Reply ]
  • can you please give me your code which is running for gmail account?    [ Reply ]
  • can you please give me your code which is running for gmail account?    [ Reply ]
  • Problem with Rediff & Hotmail    [ Reply ]
  • SMTP Authenticate    [ Reply ]
  • The Server Rejected One or more Recipient addresses.    [ Reply ]
  • How do I authenticate using SPA?    [ Reply ]
  • How to use SPA with outgoing server in asp.net version 2.0    [ Reply ]
  • Thank You!    [ Reply ]
  • Error after adding Reference    [ Reply ]
  • smtp failure handling    [ Reply ]
  • Need Help    [ Reply ]
  • HELP ME    [ Reply ]
  • authenticate to send an email, help me    [ Reply ]
  • what is the alternative of smtpauthenticate in System.Net.Mail    [ Reply ]
  • hello mail send    [ Reply ]
    • RE: hello mail send    [ Reply ]
  • reading from webconfig    [ Reply ]
  • Problem to send mail    [ Reply ]
    • RE: Problem to send mail    [ Reply ]
    • RE: Problem to send mail    [ Reply ]
  • Authentication?    [ Reply ]
  • http request    [ Reply ]
  • suggest to authenticate!!!!    [ Reply ]
  • email confirmation    [ Reply ]
    • RE: email confirmation    [ Reply ]
  • Authentication Slow    [ Reply ]
    • RE: Authentication Slow    [ Reply ]
  • How to get/set properties of send mail MAPI_DIALOG    [ Reply ]
  • enter e-mail id only in a textbox    [ Reply ]
  • Entering invalid username and password    [ Reply ]
  • smtp authentication    [ Reply ]
  • Mail went though    [ Reply ]
  • Invalid Basic logon succeeds after successful NTLM authen.    [ Reply ]
  • send mail error    [ Reply ]
  • send mail error    [ Reply ]
  • The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available    [ Reply ]
  • Send Mail    [ Reply ]
  • Mail.fields    [ Reply ]
    • RE: Mail.fields    [ Reply ]
      • RE RE: Mail.fields    [ Reply ]
  • Sending email to exterior    [ Reply ]
  • The transport failed to connect to the server!    [ Reply ]
  • Fields update failed    [ Reply ]
  • still getting authentication error..    [ Reply ]
  • cant send email    [ Reply ]