5,136,916 members and growing! (12,690 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » General     Intermediate

SMTP Authentication using System.Web.Mail (CDOSYS)

By C.Shattock

Setting CDOSYS Schema contents to permit "tricks" with System.Web.Mail
C#, VB, Windows, .NET 1.1, .NET, Visual Studio, ASP.NET, Dev

Posted: 12 Dec 2003
Updated: 12 Dec 2003
Views: 186,580
Announcements



Search    
Advanced Search
Sitemap
46 votes for this Article.
Popularity: 6.72 Rating: 4.04 out of 5
3 votes, 6.5%
1
0 votes, 0.0%
2
4 votes, 8.7%
3
4 votes, 8.7%
4
35 votes, 76.1%
5

Introduction

SMTP Authentication - expensive third party control or roll-you-own with System.Net and sockets? Not required: The CDOSYS Schema is accessible directly from your code and you can use MailMessage.Fields to access and change schema values to control the attributes of your email.

Using the code

Create your email using the MailMessage class - then set the Schema Fields of Interest to you. For example, to send via an external SMTP server on port 25 with SMTP authentication name and password:

// using System.Web.Mail;

    eMail = new MailMessage();
    eMail.BodyFormat = MailFormat.Text;
    eMail.From = _SendFrom;
    eMail.Fields[http://schemas.microsoft.com/cdo/configuration/smtsperver]

      = "SMTPServerName";
    eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
    eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendusing"]  = 2;
    if (SMTPUser != null && SMTPPassword != null)
    {
        eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
        eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendusername"] = 
  "SMTPAUTHUser";
        eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendpassword"] = 
  "SMTPAUTHPassword";
    }
    eMail.To = "recipients";
    SmtpMail.SmtpServer = SMTPServerName;
    SmtpMail.Send(eMail);
//

Check MSDN for the CDOSYS and enumerated values.

History

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

C.Shattock



Location: United Kingdom United Kingdom

Other popular .NET Framework articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 34 (Total in Forum: 34) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralBulk Emails: Does anyone know how to send multiple emails inside one connect/disconnect?memberremoteportal5:38 17 Apr '08  
GeneralError 451? Fix is here!membermd2k3:10 8 Aug '07  
GeneralIf you are having issues with authentication you want to read this...memberBrotherC10:04 31 Jan '07  
GeneralRe: If you are having issues with authentication you want to read this...memberhepsy.i0:58 26 Oct '07  
GeneralTo/From Addresses in ASP.NET Email Sendingmemberf.z10:59 25 Dec '06  
GeneralhmemberFarhan Hashmi14:08 27 Nov '06  
GeneralThis Code Does not work.... Help Me out....membernilsgate1:20 22 Jun '06  
GeneralRe: This Code Does not work.... Help Me out....memberwsdelicate8:36 28 Jun '06  
GeneralRe: SMTP Authentication using System.Web.Mail (CDOSYS)membermalharone7:25 8 Nov '05  
GeneralDoes anyone know where the cdosys schema has moved?memberdaniel1122338:07 4 Nov '05  
GeneralRe: Does anyone know where the cdosys schema has moved?memberjamiranda4:34 21 Dec '05  
Generalthank you!!!!sussansys19:43 17 Jun '05  
Generalthank youmemberfatibomba1:47 7 Apr '05  
GeneralUsing C++memberadrianodri2:08 10 Dec '04  
GeneralFantastic!memberJayDreyer11:04 23 Sep '04  
GeneralError No 451sussAnonymous23:15 31 Jul '04  
GeneralExternal SMTP Server with CDOSYSsussRameshN313:46 30 Jun '04  
GeneralRe: External SMTP Server with CDOSYSmemberfulgeras23:34 13 Jan '05  
GeneralRe: External SMTP Server with CDOSYSsussAnonymous1:49 17 Aug '05  
GeneralRe: External SMTP Server with CDOSYSsussAnonymous1:53 17 Aug '05  
GeneralCan't connect?sussAdrianFoobar1:58 22 Apr '04  
GeneralRe: Can't connect?sussAdrianFoobar4:21 22 Apr '04  
GeneralDifficulties in setting Fieldsmemberim_tct8:58 20 Apr '04  
GeneralRe: Difficulties in setting FieldssussAdrianFoobar1:36 22 Apr '04  
GeneralRe: Difficulties in setting Fieldsmemberim_tct8:35 22 Apr '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Dec 2003
Editor: Nishant Sivakumar
Copyright 2003 by C.Shattock
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project