Click here to Skip to main content
12,501,845 members (53,457 online)
Click here to Skip to main content
Add your own
alternative version

Stats

319.5K views
70 bookmarked
Posted

SMTP Authentication using System.Web.Mail (CDOSYS)

, 12 Dec 2003
Rate this:
Please Sign up or sign in to vote.
Setting CDOSYS Schema contents to permit "tricks" with System.Web.Mail

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

Share

About the Author

C.Shattock
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionHow to send email to a Group Pin
AJFK1-Oct-09 8:51
memberAJFK1-Oct-09 8:51 
Generalmails are queued in queue directory. Pin
rajeshchavan19838-Jul-09 2:51
memberrajeshchavan19838-Jul-09 2:51 
QuestionWhat about saved password in Outlook Express ? Pin
blackjack200810-Jun-09 2:13
memberblackjack200810-Jun-09 2:13 
GeneralSave mail in Sent items Pin
Pardeep Bogra16-Jun-08 3:36
memberPardeep Bogra16-Jun-08 3:36 
QuestionBulk Emails: Does anyone know how to send multiple emails inside one connect/disconnect? Pin
remoteportal17-Apr-08 4:38
memberremoteportal17-Apr-08 4:38 
GeneralError 451? Fix is here! Pin
md2k8-Aug-07 2:10
membermd2k8-Aug-07 2:10 
GeneralIf you are having issues with authentication you want to read this... Pin
BrotherC31-Jan-07 9:04
memberBrotherC31-Jan-07 9:04 
GeneralRe: If you are having issues with authentication you want to read this... Pin
hepsy.i25-Oct-07 23:58
memberhepsy.i25-Oct-07 23:58 
GeneralTo/From Addresses in ASP.NET Email Sending Pin
f.z25-Dec-06 9:59
memberf.z25-Dec-06 9:59 
Generalh Pin
Farhan Hashmi27-Nov-06 13:08
memberFarhan Hashmi27-Nov-06 13:08 
GeneralThis Code Does not work.... Help Me out.... Pin
nilsgate22-Jun-06 0:20
membernilsgate22-Jun-06 0:20 
GeneralRe: This Code Does not work.... Help Me out.... Pin
wsdelicate28-Jun-06 7:36
memberwsdelicate28-Jun-06 7:36 
GeneralRe: SMTP Authentication using System.Web.Mail (CDOSYS) Pin
malharone8-Nov-05 6:25
membermalharone8-Nov-05 6:25 
QuestionDoes anyone know where the cdosys schema has moved? Pin
daniel1122334-Nov-05 7:07
memberdaniel1122334-Nov-05 7:07 
AnswerRe: Does anyone know where the cdosys schema has moved? Pin
jamiranda21-Dec-05 3:34
memberjamiranda21-Dec-05 3:34 
Generalthank you!!!! Pin
ansys17-Jun-05 18:43
sussansys17-Jun-05 18:43 
Generalthank you Pin
fatibomba7-Apr-05 0:47
memberfatibomba7-Apr-05 0:47 
GeneralUsing C++ Pin
adrianodri10-Dec-04 1:08
memberadrianodri10-Dec-04 1:08 
GeneralFantastic! Pin
JayDreyer23-Sep-04 10:04
memberJayDreyer23-Sep-04 10:04 
GeneralError No 451 Pin
Anonymous31-Jul-04 22:15
sussAnonymous31-Jul-04 22:15 
GeneralExternal SMTP Server with CDOSYS Pin
RameshN330-Jun-04 12:46
sussRameshN330-Jun-04 12:46 
GeneralRe: External SMTP Server with CDOSYS Pin
fulgeras13-Jan-05 22:34
memberfulgeras13-Jan-05 22:34 
GeneralRe: External SMTP Server with CDOSYS Pin
Anonymous17-Aug-05 0:49
sussAnonymous17-Aug-05 0:49 
GeneralRe: External SMTP Server with CDOSYS Pin
Anonymous17-Aug-05 0:53
sussAnonymous17-Aug-05 0:53 
QuestionCan't connect? Pin
AdrianFoobar22-Apr-04 0:58
sussAdrianFoobar22-Apr-04 0:58 
AnswerRe: Can't connect? Pin
AdrianFoobar22-Apr-04 3:21
sussAdrianFoobar22-Apr-04 3:21 
GeneralDifficulties in setting Fields Pin
im_tct20-Apr-04 7:58
memberim_tct20-Apr-04 7:58 
GeneralRe: Difficulties in setting Fields Pin
AdrianFoobar22-Apr-04 0:36
sussAdrianFoobar22-Apr-04 0:36 
GeneralRe: Difficulties in setting Fields Pin
im_tct22-Apr-04 7:35
memberim_tct22-Apr-04 7:35 
GeneralRe: Difficulties in setting Fields Pin
Entrapnet28-Jan-05 17:04
memberEntrapnet28-Jan-05 17:04 
GeneralRe: Difficulties in setting Fields Pin
xlouk23-Feb-05 20:30
memberxlouk23-Feb-05 20:30 
QuestionHow about a little wrapper? Pin
JasonSmith23-Mar-04 14:41
memberJasonSmith23-Mar-04 14:41 
AnswerRe: How about a little wrapper? Pin
C.Shattock23-Mar-04 17:40
memberC.Shattock23-Mar-04 17:40 
GeneralNice tip Pin
CreProDes20-Feb-04 19:28
memberCreProDes20-Feb-04 19:28 
GeneralRe: Nice tip Pin
spidur124-Feb-04 5:33
memberspidur124-Feb-04 5:33 
GeneralRe: Nice tip Pin
fatihsx27-May-05 9:50
memberfatihsx27-May-05 9:50 
Generalsmtpserverport Pin
mattski5-Jan-04 12:58
membermattski5-Jan-04 12:58 
GeneralRe: smtpserverport Pin
C.Shattock5-Jan-04 18:47
memberC.Shattock5-Jan-04 18:47 

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

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

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