Click here to Skip to main content
12,448,164 members (48,038 online)
Click here to Skip to main content
Add your own
alternative version

Stats

92.6K views
2.3K downloads
32 bookmarked
Posted

SMTP Mailer with Authentication

, 25 Oct 2003
Rate this:
Please Sign up or sign in to vote.
.NET assembly, 100% managed code. Send mails using a SMTP server that requires authentication.

Introduction

This article describes a simple assembly to send mails programmatically using a SMTP server that requires authentication. It also works with those servers that doesn't require it.

In this release, you cannot use attachments, but I will implement it as soon as possible.

To show you how simple this component is, I'll show you it's main interface:

The main method is SendMail:

1st Overload

Used for sending a simple mail using a server without authentication. The default MailFormat is HTML.

public System.Boolean SendMail ( System.String from , System.String to , System.String subject , System.String message , System.String serverName )

2nd Overload

Used for sending a simple mail using a server with authentication. The default MailFormat is HTML.

public System.Boolean SendMail ( System.String from , System.String to , System.String subject , System.String message , System.String AUTH_Name , System.String AUTH_Password , System.String serverName )

3rd Overload

Used for sending a mail using a server with authentication. Here you can specify the MailFormat and also the server port.

public System.Boolean SendMail ( System.String from , System.String to , System.String subject , System.String message , MailFormat format , System.String AUTH_Name , System.String AUTH_Password , System.String serverName , System.Int32 port )

When the method SendMail returns false, you have an Err property that contains the Exception that originated the failure of the method call.

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

pjutard
Web Developer
United States United States
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralGmail Pin
RunnerDude6-Jul-07 8:17
memberRunnerDude6-Jul-07 8:17 
GeneralIt's working! Pin
_BlackLine_23-Apr-06 7:44
member_BlackLine_23-Apr-06 7:44 
Generaldifferent views in different Browsers Pin
Ramalinga S Reddy26-Mar-06 19:47
memberRamalinga S Reddy26-Mar-06 19:47 
GeneralI could not be able to run Pin
Ramalinga S Reddy26-Mar-06 19:34
memberRamalinga S Reddy26-Mar-06 19:34 
GeneralTime stamp says 12/31/1969 Pin
FinishedOnTime14-Mar-04 10:57
memberFinishedOnTime14-Mar-04 10:57 
GeneralGet an Error Pin
rockhopper12819-Nov-03 6:02
memberrockhopper12819-Nov-03 6:02 
GeneralRe: Get an Error Pin
pjutard19-Nov-03 6:19
memberpjutard19-Nov-03 6:19 
QuestionHow about other encoding mail? Pin
Hardy14-Nov-03 3:00
memberHardy14-Nov-03 3:00 
AnswerRe: How about other encoding mail? Pin
pjutard14-Nov-03 4:35
memberpjutard14-Nov-03 4:35 
GeneralOOP Pin
Heath Stewart26-Oct-03 18:08
editorHeath Stewart26-Oct-03 18:08 
You come from a C background, don't you? Smile | :)

Instead of using several overloads with massive amounts of parameters (especially for the body, which - if marshalled - would be very expensive), use an object. For instance, System.Web.Mail.SmtpMail uses a MailMessage class. This allows more flexibility and, perhaps, even data-binding which could be handy in mailings (not advocating SPAM here, but things like news or site updates).

Also, exceptions are used in .NET - just like in Java. the Err property is remnant of Win32, just like having to call GetLastError. Throw an Exception (preferrably your own exception class derived from Exception) with necessary information. Keeping with the .NET model helps other developers when using your libraries because it's consistent and ties in with everything else (for example, exceptions break the flow the execution and are automatic, where error checking is does not break the flow and is not automatic).

Just some suggestions for a better object-oriented design (since .NET is truly object-oriented) and for consistency with the .NET base class library and the general framework model.

 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: OOP Pin
pjutard26-Oct-03 18:37
memberpjutard26-Oct-03 18:37 
GeneralRe: OOP Pin
Heath Stewart26-Oct-03 18:50
editorHeath Stewart26-Oct-03 18:50 
GeneralRe: OOP Pin
pjutard27-Oct-03 2:16
memberpjutard27-Oct-03 2:16 
GeneralRe: OOP Pin
alpy26-Mar-07 8:09
memberalpy26-Mar-07 8:09 

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.160811.3 | Last Updated 26 Oct 2003
Article Copyright 2003 by pjutard
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid