Click here to Skip to main content
Licence 
First Posted 12 Dec 2003
Views 277,796
Bookmarked 70 times

SMTP Authentication using System.Web.Mail (CDOSYS)

By C.Shattock | 12 Dec 2003
Setting CDOSYS Schema contents to permit "tricks" with System.Web.Mail
3 votes, 6.4%
1

2
4 votes, 8.5%
3
4 votes, 8.5%
4
36 votes, 76.6%
5
4.76/5 - 47 votes
3 removed
μ 4.05, σa 1.93 [?]

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



United Kingdom United Kingdom

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to send email to a Group PinmemberAJFK9:51 1 Oct '09  
Generalmails are queued in queue directory. Pinmemberrajeshchavan19833:51 8 Jul '09  
QuestionWhat about saved password in Outlook Express ? Pinmemberblackjack20083:13 10 Jun '09  
GeneralSave mail in Sent items PinmemberPardeep Bogra4:36 16 Jun '08  
QuestionBulk Emails: Does anyone know how to send multiple emails inside one connect/disconnect? Pinmemberremoteportal5:38 17 Apr '08  
GeneralError 451? Fix is here! Pinmembermd2k3:10 8 Aug '07  
GeneralIf you are having issues with authentication you want to read this... PinmemberBrotherC10:04 31 Jan '07  
GeneralRe: If you are having issues with authentication you want to read this... Pinmemberhepsy.i0:58 26 Oct '07  
GeneralTo/From Addresses in ASP.NET Email Sending Pinmemberf.z10:59 25 Dec '06  
Generalh PinmemberFarhan Hashmi14:08 27 Nov '06  
GeneralThis Code Does not work.... Help Me out.... Pinmembernilsgate1:20 22 Jun '06  
GeneralRe: This Code Does not work.... Help Me out.... Pinmemberwsdelicate8:36 28 Jun '06  
GeneralRe: SMTP Authentication using System.Web.Mail (CDOSYS) Pinmembermalharone7:25 8 Nov '05  
QuestionDoes anyone know where the cdosys schema has moved? Pinmemberdaniel1122338:07 4 Nov '05  
AnswerRe: Does anyone know where the cdosys schema has moved? Pinmemberjamiranda4:34 21 Dec '05  
Generalthank you!!!! Pinsussansys19:43 17 Jun '05  
Generalthank you Pinmemberfatibomba1:47 7 Apr '05  
GeneralUsing C++ Pinmemberadrianodri2:08 10 Dec '04  
GeneralFantastic! PinmemberJayDreyer11:04 23 Sep '04  
GeneralError No 451 PinsussAnonymous23:15 31 Jul '04  
GeneralExternal SMTP Server with CDOSYS PinsussRameshN313:46 30 Jun '04  
GeneralRe: External SMTP Server with CDOSYS Pinmemberfulgeras23:34 13 Jan '05  
GeneralRe: External SMTP Server with CDOSYS PinsussAnonymous1:49 17 Aug '05  
GeneralRe: External SMTP Server with CDOSYS PinsussAnonymous1:53 17 Aug '05  
QuestionCan't connect? PinsussAdrianFoobar1:58 22 Apr '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 13 Dec 2003
Article Copyright 2003 by C.Shattock
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid

The Daily Insider