04 April 2013

How to send e-mail manually using Telnet.exe or PowerShell

Let’s say, you want to send an e-mail to someone@hotmail.com. Then you need to act like a e-mail server.

First of all you need to know which servers serve the e-mail domain (the part after the @ sign). It’s done by using MX records on DNS servers. In our case the domain is hotmail.com. To get the MX records use this command:

nslookup -q=mx hotmail.com 8.8.8.8

image

The host 8.8.8.8 is good address for external DNS lookups, “hotmail.com” is the domain name and “-q=mx” says nslookup to request only MX records.

The answer section contains several MX records. If you get 0 results, then you cannot proceed (maybe there is a typo in domain name or you don’t have UDP 53 port open to DNS server or something else). Smaller MX preferences mean higher priority. E-mail servers try lower value servers first and if unsuccessful, then use higher value MX records to send e-mails.

Next you need to start “telnet mx1.hotmail.com 25” (you can use any server of those 4 MX records because they all are same priority). When the connection succeeds, type following commands:

helo
mail from:senders@address.com
rcpt to:someone@hotmail.com
data
subject: test

whatever
.
quit

image

After each line press Enter. Don’t use backspace, because Windows’ telnet.exe doesn’t transmit data at the end of a line, but each character individually. If you fail, press Enter and type the line again (use putty.exe if you need to use backspace).

HELO command needs sometimes the “hostname” after the HELO word separated by space. You can type anything in this place, but some anti-spam measures might want you to use some real name (you can use http://myip.eu to figure out the right hostname to use on your computer).

MAIL and RCPT commands require sometimes e-mail addresses to be inside angle brackets <>. DATA command starts actual e-mail content. You can use just Subject part in the header. Empty line is needed between the header and message body section. Message body will end with a line with a dot (.) as the only character on the line.

If you need to test same stuff more often, then you probably use PowerShell to send the message (instead of Telnet). The command line is pretty simple:

Send-MailMessage -SmtpServer mx1.hotmail.com -To someone@hotmail.com -From senders@address.com -Subject "test" -Body "whatever"

image

No comments:

Post a Comment