HotMail SMTP Service

BillSoo
09-17-2001, 12:29 PM
A tutorial submitted by ChiefRedBull


###################################
# #
# HOTMAIL SMTP SERVICE TUTORIAL #
# v2.0 #
# by Chief #
# #
###################################


Welcome to the Hotmail tutorial. This will teach you
how to use the free Simple Mail Transfer Protocol service
that Hotmail provides.

To use this service you must be able to connect to
the server. This is easy via telnet or even Visual Basic.


####################
Through Telnet
####################


Simple Mail Transfer Protocol goes through Port 25, so
through Telnet, connect to:
mail.hotmail.com
Port: 25
Once connected you will get the following message:
220-HotMail (NO UCE) ESMTP server ready at <the date>
220 EMSTP spoken here
Upon receipt of this message, you have to say hello to
the server so type:
HELO hotmail.com
This will provoke the response:
250 Requested mail action ok, completed
Now the pleasantries are over with, we're ready for the
sending of the mail. There are several commands you need to know.
They are

MAIL FROM: <user@host.com>
RCPT TO: <user@host.com>
DATA
SUBJECT:
TO:
FROM:

Thats it really. Its very simple. You beign by specifying the

MAIL FROM: <user@host.com>

After each successful communication with hotmail, it will send back
a response. If its an error, merely retype the command you typed,
only more carefully this time. The response looks like this:

500 Syntax error, command unrecognized

Thje successfull message looks like this:

250 Requested mail action okay, completed

So if you got a good response, now specify the

RCPT TO: <user@host.com>

If you didn't get a good response. Try again.
Next, type the

DATA

command. This will provoke the following:

354 Start mail input; end with <CRLF>.<CRLF>

So first fill out your <TO:> <FROM:> and <SUBJECT:> fields,
in any order you want. Then leave a line, type your message,
then put a "." on a line by itself and hit return again.
If the server responds with the good old:

250 Requested mail action okay, completed

Then you're done. Mail sent.


Here is a sample output from a mail:

--------------------------------------------------------------------------------
220-HotMail (NO UCE) ESMTP server ready at Sun, 16 Sep 2001 09:04:19 -0700
220 ESMTP spoken here
helo zippy.com
250 Requested mail action okay, completed
mail from: test@hotmail.com
250 Requested mail action okay, completed
rcpt to: test@hotmail.com
250 Requested mail action okay, completed
data
354 Start mail input; end with <CRLF>.<CRLF>
Subject: Test
To: test
From: test

this would be the body
.
250 Requested mail action okay, completed
quit
--------------------------------------------------------------------------------



#####################
THROUGH VB
#####################

Visual Basic is just as simple to use. All you have to do
is connect to the SMTP server on port twenty five, and send
the appropriate commands. Hotmail will send back any responses
to your winsock, so you can add a display function to your
Winsock1_DataArrival event to show you whats going on.
To send a command, simply use the following:

Winsock1.SendData "HELO hotmail.com"

OR

Winsock1.SendData "MAIL FROM: " & txtMailFrom.text

It should be fairly easy to figure out the rest in VB.
All you have to do is simulate the actions through a telnet
session.
I would advise a little error checking thouugh. Every time
you get a response from hotmail, check it wasn't an error
( this can be done by checking the number at the start of
the string (500 - syntax error) using the instr() function))
and only if its an OK response (250) then should you send the
next part.

Sample code

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

Private Sub mnuConnect_Click()
' specify the location to connect to
Sock.RemoteHost = "mail.hotmail.com"
Sock.RemotePort = 25
' connect
Sock.Connect
' loop while its not connected
Do While Sock.State <> sckConnected
DoEvents
' if its failed
If Sock.State = sckError Then
MsgBox "Connection Failed"
Exit Sub
End If
Loop
End Sub

Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
Dim sData As String

' get the incoming data
Sock.GetData sData
' display it
txtMain.SelText = sData
End Sub

Private Sub txtOutgoing_KeyPress(KeyAscii As Integer)
' if the user pressed "{ENTER}"
If KeyAscii = 13 Then
' send what youve typed
Sock.SendData txtOutgoing.Text & vbCrLf
' display it in the main box
txtMain.SelText = txtOutgoing.Text & vbCrLf
' clear the lower box
txtOutgoing.Text = vbNullString
' neutralise the vbCrLf
KeyAscii = 0
End If
End Sub
--------------------------------------------------------------------

(I've attached this project for y'all delight...)



Easy huh?

Will












###########################################################
I welcome your comments, suggestions, or just plain hate
mail. PM to "ChiefRedBull" on www.visualbasicforum.com
############################################################





"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

ChiefRedBull
02-17-2002, 05:47 AM
Attached is a working example of how to use the Winsock Control to facilitate a telnet client.

Also attached is the tutorial shown above.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum