7is7.com > Software > SMTP via Telnet
Linux Penguin

SMTP via Telnet

This page is more of a memo to myself and not intended as a guide or anything. So just see it as notes that I share with whoever is interested.

Send an e-mail using telnet

Here is how to send an e-mail using telnet. This can be used to test mail servers, for instance I use it to test if my backup mail server works.

telnet mx3.zoneedit.com 25
Trying 71.6.145.17...
Connected to mx3.zoneedit.com.
Escape character is '^]'.
220 mx3.zoneedit.com ESMTP Postfix
HELO galaxy
250 mx3.zoneedit.com
MAIL FROM:<someone@somedomain.com>
250 2.1.0 Ok
RCPT TO:<me@mydomain.com>
250 2.1.5 Ok
DATA
354 End data with .
From:someone@somedomain.com
To:me@mydomain.com
Subject:Testing mx3.zoneedit.com

Testing: mx3.zoneedit.com
Timestamp: 2012-05-02 03:48:40
.
250 2.0.0 Ok: queued as 18FB34308F6
quit
221 2.0.0 Bye
Connection closed by foreign host.

Here is a short expect script that automates the process for any mx server. It needs to be called with 3 command line arguments: an mx server, a sender e-mail address and a recipient e-mail address.

#! /usr/bin/expect

set timeout 20
set server [lindex $argv 0]
set sndr_mail [lindex $argv 1]
set rcpt_mail [lindex $argv 2]
set ts [timestamp -format "%Y-%m-%d %H:%M:%S"]

spawn telnet $server 25

expect "Connected to "
expect "220 "
send "HELO galaxy\n"
expect "250 "
send "MAIL FROM:<$sndr_mail>\n"
expect "250 "
send "RCPT TO:<$rcpt_mail>\n"
expect "250 "
send "DATA\n"
expect "354 "
send "From:$sndr_mail\n"
send "To:$rcpt_mail\n"
send "Subject:Testing $server\n\n"
send "Testing: $server\n"
send "Timestamp: $ts\n"
send ".\n"
expect "250 "
send "quit\n"
expect "221 "

# TIAF!

 


Linux user 425492

Get Firefox! Download LibreOffice Use Fedora