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!
LVL 5
KDivadAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
Thanks! Locking the question...
0
 
sdland1Commented:
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
0
 
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
KDivadAuthor Commented:
Nope! Sometimes I can pick what I need out of another language, but not this time.

Thanks anyway,
0
 
mcriderCommented:
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)>
   DATA
   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)
   QUIT

----------------------------------------------------------------------------------------------------------------------------------------------------------------

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-
   214-      Supported commands:
   214-
   214-           EHLO     HELO     MAIL     RCPT     DATA
   214-           VRFY     RSET     NOOP     QUIT
   214-
   214-      SMTP Extensions supported through EHLO:
   214-
   214-           EXPN     HELP     SIZE
   214-
   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!


Cheers!
0
 
mcriderCommented:
By the way, see the following answered questions:

(2 points) how to dial a connection
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10250593 

(7 points) uuencode
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10249375 

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...


Cheers!

0
 
mcriderCommented:
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.


Cheers!



THE CODE:

    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
            DoEvents
            .SendData "MAIL FROM: <" + FromAddr + ">" + vbCrLf
            DoEvents
            .SendData "RCPT TO: <" + ToAddr + ">" + vbCrLf
            DoEvents
            .SendData "DATA" + vbCrLf
            DoEvents
            .SendData "SUBJECT: " + Subject + vbCrLf
            DoEvents
            .SendData "FROM: " + FromAddr + vbCrLf
            DoEvents
            .SendData "REPLY-TO: <" + ToAddr + ">" + vbCrLf
            DoEvents
            .SendData "DATE: " + CStr(Now) + vbCrLf + vbCrLf
            DoEvents
            .SendData Msg + vbCrLf + vbCrLf + vbCrLf
            DoEvents
            If Not Attachment = "" Then
                DoEvents
                fNum = FreeFile
                Open Attachment For Binary Access Read As fNum
                AttachData = Space(LOF(fNum))
                Get #fNum, , AttachData
                Close #fNum
                .SendData AttachData
                DoEvents
            End If
            .SendData vbCrLf + vbCrLf + "." + vbCrLf
            DoEvents
            .SendData "QUIT" + vbCrLf
            DoEvents
        End With
    End Sub
0
 
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?
0
 
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.

Later,
KDivad
0
 
mcriderCommented:
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... ;-)


Cheers!
0
 
KDivadAuthor Commented:
Adjusted points to 125
0
 
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?

Late,
0
 
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!
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
 
mcriderCommented:
By the way, did you get UUENCODED attachments to work?


Cheers!
0
 
KDivadAuthor Commented:
I hadn't tried them yet.
0
All Courses

From novice to tech pro — start learning today.