E-Mail without MAPI/OCXs/DLLs

PLEASE DON'T LOCK THIS QUESTION WITH AN ANSWER! Post only comments and I'll accept the best (or some of the best) of them. I will probably reject all answers before reading them. If I like the answer, I'll ask for a repost.

This is mostly just for learning experience, because I have a few points to spare and I'm curious. I would like to know how to send and recieve email without using MAPI or any add-on components. I would have never thought it to be a fairly simple task, but I've seen code pieces posted by mcrider that show it to be rather simple because it's basically just plain text commands (HELO(sp?), etc.).
What I'm after is step-by-step type info. i.e.
1. Activate DUN.
2. Log-in (domain, port, username, password, etc.).
3. Check for email.
4. Get headers/delete emails/download/upload/etc.
5. Format EMLs properly including/excluding attachments/MIME/UUEncode/body/subject/etc.
6. etc, etc.

Basically, I want to know all the stuff needed for a basic email client.

NO (well...probably no) answers that include/require any dlls, ocxs or (M)APIs (except for winsock) will be excepted, so PLEASE don't suggest them.

Points are low, I know, but that's in case I need to split them up. (Check my profile if you want, I have a habit of posting a new question with more points for the answerer.)

Thanks a million in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

well if you knew perl ive got a project exactly like hotmail at http://lightning.prohosting.com/~shell123/ dont know about VB with no API if youd like to see the project search the full apps section for SMTP or EMAIL
KDivadAuthor Commented:
It does make me curious, but I'm afraid I don't know any perl, so it probably won't help. I'll take a look, though, because it might help anyway.
KDivadAuthor Commented:
Nope! Sometimes I can pick what I need out of another language, but not this time.

Thanks anyway,
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Hello KDivad!

I see my name in the question, so I figured I would post... ;-)

I woln't go into how to use the winsock control, because I think you already know how to do that... If not, let me know...


Sending and receive mail using winsock is a really simple task...

Basically there are two protocols you need to worry about:  SMTP and POP3.

SMTP (Simple Mail Transfer Protocol) is used to send messages from a client to a mail server.  The client initiates the connection to the mailserver using TCP port 25.

POP3 (Post Office Protocol version 3) is used to retrieve messages from a mail server by a client.  The client initiates the connection to the mailserver using TCP port 110.

You are correct... the protocol commands are ASCII commands.  without writing any code at all, you can see how these commands work by using the TELNET.EXE command.  To send a quick message to yourself, do this in a DOS console window:

    TELNET mailserver 25

Remember to replace "mailserver" in the command above with the actual name of your mail server.  Once the telnet program starts you should see a message like this:

    220 mail.rdcx.md.home.com ESMTP server (InterMail v4.01.01.00 201-229-111) ready
 Sat, 29 Jan 2000 18:29:40 -0800

Type in the following lines into the TELNET session.  Press the enter key after each line.  Be very careful typing in the commands because you can't backspace over an error. Anywhere you see a < or > symbol, you need to use that actual character. Replace anything you see in parenthesis (including the parenthesis) with what the comment describes:

   HELO(put a space here)
   MAIL FROM: <(something like KDivad@here.com)>
   RCPT TO: <(the address of who this message is to)>
   FROM: (whatever full name you want to show in the from line)
   REPLY-TO: <(whatever address you want replies to go to)>
   SUBJECT: (whatever the subject is)
   (press enter again to get a blank line)
   (this is where the body of the message goes, as many lines as you want. when you're done with the message, hit the enter key, then press . and hit the enter key again)


Most SMTP servers support HELP command.  This will show all of the commands supported by the mail server.  Once you've sent your message this way, wait a few minutes and then go check your email...

The SMTP server will respond with 3-digit numbered messages. like:

   250 Sender <mcrider@caas.com> Ok

If there is a - after the message number, there is another message line that will be coming from the server, like this (notice the last message number doesn't have the "-"):

   214-This SMTP server is a part of the InterMail E-mail system.  For
   214-information about InterMail, please see http://www.software.com
   214-      Supported commands:
   214-           EHLO     HELO     MAIL     RCPT     DATA
   214-           VRFY     RSET     NOOP     QUIT
   214-      SMTP Extensions supported through EHLO:
   214-           EXPN     HELP     SIZE
   214-For more information about a listed topic, use "HELP <topic>"
   214 Please report mail-related problems to Postmaster at this site.


Now on to POP3... POP3 can be tested just like SMTP using: TELNET mailserver 110

POP3 servers do not support a HELP command, so here are all of the commands you can send:

   USER username         -indicates the user's mailbox you are checking.  This must be sent first.

   PASS password         -sends the password for the mailbox. This must be sent after the USER command.

   STAT                  -request the number of messages and size of mail drop in octets.

   LIST [msg]            -request the size of a specific message or all messages if msg is not specified.

   RETR msg              -request the actual message.

   DELE msg              -delete a specified message from the server.

   NOOP                  -does nothing

   RSET                  -request that the server reset all deletion requests

   QUIT                  -quits the session and deletes any messages marked for deletion

   TOP msg n             -request that the server return the first n lines of the message msg.

   UIDL msg              -returns a unique ID string for the requested message or all message if msg is not specified.

Hope this helps!

By the way, see the following answered questions:

(2 points) how to dial a connection

(7 points) uuencode

As far as attaching a file to a message is concerned, all you need to do is UUENCODE the file and then make the uuencoded file part of the message body.  Make sure you put a blank line before you send the uuencoded file.

I would stick with uuencoding instead of MIME... It's much easier...


By the way, here is a subroutine that will send a message with attachment to an SMTP Server...  This subroutine assumes that you have already connected to the mail server with Winsock1.  The attachment must be a file that has already been uuencoded.



    Sub SendMessage(FromAddr As String, ToAddr As String, Subject As String, Msg As String, Attachment As String)
        Dim fNum As Integer
        Dim AttachData As String
        With Winsock1
            .SendData "HELO " + CStr(.LocalIP) + vbCrLf
            .SendData "MAIL FROM: <" + FromAddr + ">" + vbCrLf
            .SendData "RCPT TO: <" + ToAddr + ">" + vbCrLf
            .SendData "DATA" + vbCrLf
            .SendData "SUBJECT: " + Subject + vbCrLf
            .SendData "FROM: " + FromAddr + vbCrLf
            .SendData "REPLY-TO: <" + ToAddr + ">" + vbCrLf
            .SendData "DATE: " + CStr(Now) + vbCrLf + vbCrLf
            .SendData Msg + vbCrLf + vbCrLf + vbCrLf
            If Not Attachment = "" Then
                fNum = FreeFile
                Open Attachment For Binary Access Read As fNum
                AttachData = Space(LOF(fNum))
                Get #fNum, , AttachData
                Close #fNum
                .SendData AttachData
            End If
            .SendData vbCrLf + vbCrLf + "." + vbCrLf
            .SendData "QUIT" + vbCrLf
        End With
    End Sub
KDivadAuthor Commented:
I attempted a little test using telnet. The first command I sent was HELO. I immediately got this back: "501 helo requires domain address" (without the quotes, of course). I tried sending without that first line and it did work, though not exactly as planned. I entered the from name as "KDivad Leahcim" (again, no quotes). I retrieved the email and found this:
"Warning: (blah, blah, blah...) didn't use HELO protocol
from: KDivad.Leahcim@xxxxx.xxx.xxx.xxx" (x'ed out just in case, but it is an address I don't recognize, although the last two sections are the correct domain).

Any ideas?
KDivadAuthor Commented:
Never mind. I figured those out.
HELO (ip address)
FROM: KDivad Leahcim <me@them.com>

Give me about 2 days to work through this and see what else (if anything) I need help with and I'll get back to you.

Yea, some mailservers do reverse address resolution.  This means they require you to say who you are on the HELO line by doing:

   HELO (ip address)

They will then check the IP address you specified in the HELO line against the IP address they can get from the GETADDR call.  If they are truely SPAM paranoid, then they will also check if the IP address passed on the HELO line is part of their domain... Meaning that only people that belong to the domain can use the mail server...

Let me know if you need any more help...

By the way, don't you think this question is worth alittle more... ;-)

KDivadAuthor Commented:
Adjusted points to 125
KDivadAuthor Commented:
Slowly figuring it out. I MIGHT have all the info I need now, but I want to shake it some more and see what falls out. You can go ahead and lock it if you want.

Yeah, it's worth more...I just hadn't upped the points yet. That should be a little better, don't you think?

Thanks! Locking the question...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KDivadAuthor Commented:
I think I've got enough. I've successfully sent myself several emails through the use of WinSock, so I should be able to figure the rest out by peeking in some eml files.

Many thanks!
Thanks for the points! Glad I could help!

By the way, did you get UUENCODED attachments to work?

KDivadAuthor Commented:
I hadn't tried them yet.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.