Click here to Skip to main content
12,451,446 members (48,070 online)
Click here to Skip to main content
Add your own
alternative version

Stats

88.5K views
603 downloads
55 bookmarked
Posted

SMTP Login class

, 21 Jan 2003
Rate this:
Please Sign up or sign in to vote.
Basic SMTP Login class

Introduction

If you are like me, you have found many SMTP classes and none have dealt with Auth Login. Those that do deal with Auth Login usually come with a fee. Using some java code that I found and the SMTP RFC , I have hashed together a very basic SMTP class that handles Auth Login.

Using the code

First lets look at how SMTP works. The RFC can be found here: RFC

  1. Connect to Server
  2. Say Helo
  3. Tell the server you wish to authenticate and how
  4. Tell the server your username (64bit encoded)
  5. Tell the server your password (64bit encoded)
  6. Send the email
  7. Disconnect from the server.

Connecting to the server

There are several different methods of authentication available. And the method your server uses may differ from the one I show here. Telneting to the server on port 25, you can type "ehlo" as your greeting and you will receive a list of the valid authentication types back. I do this as my greeting watching for "250 OK" before I continue. On some servers you may not be able to use the "ehlo" command as your primary greeting and should modify the class to use " HELO " method.

The only truly important thing to remember here is that the username and password must be 64bit encoded.

string EncodedUserName = Convert.ToBase64String(Encoder.GetBytes(UserName));
string EncodedPassword = Convert.ToBase64String(Encoder.GetBytes(Password));

Once authenticated to the server you can now begin sending the message. There are several steps in sending a message. First you have to tell the server who is sending the message. On most servers this must be the same person that logged in.

MAIL FROM: <youremail@yourdomain.com> <CRLF> 

Next, the server must be told who is to get the message.

RCPT TO: <rcptemail@theirdomain.com> <CRLF> 

Sending the Message

The server now knows who it is receiving mail from and who it should send the mail to. However it does not know what to send. To tell the server that it is about to receive the message we must send the "DATA" tag

DATA<CRLF> 

The server now knows that it is receiving message data. There are several commands that are valid here. I am only going to cover sending a subject and the actual message.

To send the subject, simply send the "Subject: " command followed by a string.

Subject: <Message Subject><CRLF> 

At this point you are ready to send the message. Simply send it as single string to the server. Not much else to it. Remember to follow the message with a <CRLF> to tell the server your done.

Closing the Message

Now that the server has the message, we have send it on it's merry way. This is done by sending a single period to the server.

.<CRLF> 

Points of Interest

The source code that I have for download also includes my basic server class. I know it's not the best so please don't flame for it Smile | :) Enjoy!!!

History

  • This is a first revision

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

Benjamin L. Miller
United States United States
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
NewsRedesigned code + 3 bug fixes [modified] Pin
JohnnyUT30-Jan-08 12:07
memberJohnnyUT30-Jan-08 12:07 
GeneralSMTP Login class FIX... Pin
theBuck9-Nov-04 9:55
membertheBuck9-Nov-04 9:55 
GeneralAuth login Pin
trongnd30-May-04 20:53
membertrongnd30-May-04 20:53 
GeneralRe: Auth login Pin
Benjamin L. Miller10-Jun-05 20:17
memberBenjamin L. Miller10-Jun-05 20:17 
GeneralAUTH LOGIN Pin
Alex Rovner29-Apr-04 5:36
memberAlex Rovner29-Apr-04 5:36 
GeneralRe: AUTH LOGIN Pin
Anonymous23-Jan-05 15:36
sussAnonymous23-Jan-05 15:36 
GeneralServer Timeout Note Pin
yfisaqt31-Mar-04 19:09
memberyfisaqt31-Mar-04 19:09 
GeneralThank you Pin
shivpal14-Oct-03 19:31
membershivpal14-Oct-03 19:31 
QuestionBusy waiting? Pin
stevex18-May-03 2:04
memberstevex18-May-03 2:04 
GeneralAdding attachments Pin
rkendall24-Apr-03 17:19
memberrkendall24-Apr-03 17:19 
QuestionCram MD5? Pin
kalme29-Jan-03 6:33
memberkalme29-Jan-03 6:33 
AnswerRe: Cram MD5? Pin
Benjamin L. Miller30-Jan-03 7:02
memberBenjamin L. Miller30-Jan-03 7:02 
GeneralAnother SMTP library with the sockets Pin
Sebastien Curutchet22-Jan-03 20:21
memberSebastien Curutchet22-Jan-03 20:21 
GeneralRe: Another SMTP library with the sockets Pin
GriffonRL23-Jan-03 2:40
memberGriffonRL23-Jan-03 2:40 

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.160826.1 | Last Updated 22 Jan 2003
Article Copyright 2003 by Benjamin L. Miller
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid