SMTP: Difference between revisions
Jump to navigation
Jump to search
Using
No edit summary |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Testing SMTP == |
== Testing SMTP == |
||
=== Commands === |
|||
* [[Linux Commands#mail]]. |
|||
=== Tools === |
=== Tools === |
||
Same as for [[IMAP#Tools|testing IMAP]]. |
Same as for [[IMAP#Tools|testing IMAP]]. |
||
Line 12: | Line 15: | ||
helo srv1.dpetri.net |
helo srv1.dpetri.net |
||
<font color="gray">250 srv1.dpetri.net Hello [192.168.0.100]</font> |
<font color="gray">250 srv1.dpetri.net Hello [192.168.0.100]</font> |
||
mail from: admin@petri.co.il |
mail from: <admin@petri.co.il> |
||
<font color="gray">250 2.1.0 admin@petri.co.il....Sender OK</font> |
<font color="gray">250 2.1.0 admin@petri.co.il....Sender OK</font> |
||
rcpt to: danielp@dpetri.net |
rcpt to: <danielp@dpetri.net> |
||
<font color="gray">250 2.1.5 danielp@dpetri.net</font> |
<font color="gray">250 2.1.5 danielp@dpetri.net</font> |
||
data |
data |
||
Line 27: | Line 30: | ||
quit |
quit |
||
<font color="gray">221 2.0.0 srv1.dpetri.net Service closing transmission channel</font> |
<font color="gray">221 2.0.0 srv1.dpetri.net Service closing transmission channel</font> |
||
;Troubleshoot |
|||
* Error <code>address does not conform to RFC 2821 syntax</code> |
|||
:Must use addresses formatted with <code><...></code>, like <code><first.last@domain.com></code>. |
|||
=== Using <code>mail</code> === |
|||
Install either package: |
|||
<source lang=bash> |
|||
sudo apt-get install mailutils # ...OR... |
|||
sudo apt-get install heirloom-mailx |
|||
</source> |
|||
Then test smtp: |
|||
<source lang=bash> |
|||
mail localuser # Send e-mail to localuser (on local machine) |
|||
mail -r sender localuser@localhost # Send e-mail with given sender |
|||
</source> |
|||
== AUTH PLAIN test script == |
|||
See [http://qmail.jms1.net/test-auth.shtml] (more information at [http://www.fehcom.de/qmail/smtpauth.html]) |
|||
First we need to compute the authentication string for the PLAIN authentication (this requires perl with MIME64 module installed): |
|||
<source lang="bash"> |
|||
# Don't forget to escape any '@' in the perl string or it shall be interpret as an array variable!!! |
|||
perl -MMIME::Base64 -e 'print encode_base64("\000jms1\@jms1.net\000not.my.real.password")' |
|||
# AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ= |
|||
</source> |
|||
Example of script: |
|||
<source lang="bash"> |
|||
nc smtp.server.org 587 |
|||
</source> |
|||
{{gray|220 smtp.server.org ESMTP Postfix}} |
|||
ehlo griffin.hell |
|||
{{gray|250-smtp.priorweb.be}} |
|||
{{gray|250-PIPELINING}} |
|||
{{gray|250-SIZE}} |
|||
{{gray|250-VRFY}} |
|||
{{gray|250-ETRN}} |
|||
{{gray|250-STARTTLS}} |
|||
{{gray|250-AUTH PLAIN LOGIN}} |
|||
{{gray|250-AUTH=PLAIN LOGIN}} |
|||
{{gray|250-ENHANCEDSTATUSCODES}} |
|||
{{gray|250 8BITMIME}} |
|||
AUTH PLAIN AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ= |
|||
{{gray|235 2.7.0 Authentication successful}} |
|||
mail from: jms1@jms1.net |
|||
{{gray|250 2.1.0 Ok}} |
|||
rcpt to: jms1@jms1.net |
|||
{{gray|250 2.1.5 Ok}} |
|||
data |
|||
{{gray|354 End data with <CR><LF>.<CR><LF>}} |
|||
from: Jimmy <jms1@jms1.net> |
|||
to: Jimmy <jms1@jms1.net> |
|||
subject: test |
|||
test |
|||
. |
|||
{{gray|250 ok 1311459496 qp 15928}} |
|||
quit |
|||
{{gray|221 2.0.0 Bye}} |
|||
Note: '''EHLO''' is the more advanced helo command, that also lists the features supported by the server. |
|||
== [[Linux_Commands#expect|Expect]] script for testing SMTP == |
|||
From [http://petervibert.com/articles/2/]. Usage: |
|||
<source lang="bash"> |
|||
expect mail.exp smtp.server.org from@address.org to@address.org |
|||
</source> |
|||
The script (<tt>mail.exp</tt>): |
|||
<source lang="bash"> |
|||
#!/usr/bin/expect |
|||
set mailserver [lrange $argv 0 0] |
|||
set from [lrange $argv 1 1] |
|||
set to [lrange $argv 2 2] |
|||
spawn telnet $mailserver 25 |
|||
expect "failed" { |
|||
send_user "$mailserver: connect failed\n" |
|||
exit |
|||
} "2?? *" { |
|||
} "4?? *" { |
|||
exit |
|||
} "refused" { |
|||
send_user "$mailserver: connect refused\n" |
|||
exit |
|||
} "closed" { |
|||
send_user "$mailserver: connect closed\n" |
|||
exit |
|||
} timeout { |
|||
send_user "$mailserver: connect to port 25 timeout\n" |
|||
exit |
|||
} |
|||
send "HELO foo.com\r" |
|||
expect "2?? *" { |
|||
} "5?? *" { |
|||
exit |
|||
} "4?? *" { |
|||
exit |
|||
} |
|||
send "MAIL FROM: <$from>\r" |
|||
expect "2?? *" { |
|||
} "5?? *" { |
|||
exit |
|||
} "4?? *" { |
|||
exit |
|||
} |
|||
send "RCPT TO: <$to>\r" |
|||
expect "2?? *" { |
|||
} "5?? *" { |
|||
exit |
|||
} "4?? *" { |
|||
exit |
|||
} |
|||
send "DATA\r" |
|||
expect "3?? *" { |
|||
} "5?? *" { |
|||
exit |
|||
} "4?? *" { |
|||
exit |
|||
} |
|||
send "From: $from\r" |
|||
send "To: $to\r" |
|||
send "Subject: test\r" |
|||
send "This is a test message\r" |
|||
send ".\r" |
|||
expect "2?? *" { |
|||
} "5?? *" { |
|||
exit |
|||
} "4?? *" { |
|||
exit |
|||
} |
|||
send "QUIT\r" |
|||
exit |
|||
</source> |
|||
== Bash script for testing SMTP == |
|||
This uses the [[Bash#TCP/UDP_devices|TCP/UDP devices available in Bash]]: |
|||
<source lang="bash"> |
|||
#! /bin/bash |
|||
# |
|||
# Usage: smtp.sh mail.server.org from@address.org to@address.org |
|||
MAILSERVER=$1 |
|||
FROM=$2 |
|||
TO=$3 |
|||
exec 5<>/dev/tcp/${MAILSERVER}/25 |
|||
cat <&5 & |
|||
sleep 1 |
|||
echo -e "HELO dummy.domain" >&5 |
|||
sleep 1 |
|||
echo -e "MAIL FROM: $FROM" >&5 |
|||
sleep 1 |
|||
echo -e "RCPT TO: $TO" >&5 |
|||
sleep 1 |
|||
echo -e "DATA" >&5 |
|||
sleep 1 |
|||
echo -e "subject: test bash" >&5 |
|||
echo -e "" >&5 |
|||
echo -e "test bash" >&5 |
|||
echo -e "." >&5 |
|||
sleep 1 |
|||
echo -e "QUIT" >&5 |
|||
sleep 1 |
|||
</source> |
Latest revision as of 17:04, 4 June 2017
Testing SMTP
Commands
Tools
Same as for testing IMAP.
Test scripts
Simple test script found by Googling...
> telnet server 25 220 srv1.dpetri.net Microsoft ESMTP MAIL Service, Version: 5.0.2195.5329 ready at Sun, 15 Sep 2002 23:51:06 +0200 helo srv1.dpetri.net 250 srv1.dpetri.net Hello [192.168.0.100] mail from: <admin@petri.co.il> 250 2.1.0 admin@petri.co.il....Sender OK rcpt to: <danielp@dpetri.net> 250 2.1.5 danielp@dpetri.net data 354 Start mail input; end with <CRLF>.<CRLF> subject: this is a test Hi Daniel I'm trying to test this connection from Telnet. Let me know if you get this message. . 250 2.6.0 <SRV1zNQZO0KheDSZeTd00000002@srv1.dpetri.net> Queued mail for delivery quit 221 2.0.0 srv1.dpetri.net Service closing transmission channel
- Troubleshoot
- Error
address does not conform to RFC 2821 syntax
- Must use addresses formatted with
<...>
, like<first.last@domain.com>
.
Using mail
Install either package:
sudo apt-get install mailutils # ...OR...
sudo apt-get install heirloom-mailx
Then test smtp:
mail localuser # Send e-mail to localuser (on local machine)
mail -r sender localuser@localhost # Send e-mail with given sender
AUTH PLAIN test script
See [1] (more information at [2])
First we need to compute the authentication string for the PLAIN authentication (this requires perl with MIME64 module installed):
# Don't forget to escape any '@' in the perl string or it shall be interpret as an array variable!!!
perl -MMIME::Base64 -e 'print encode_base64("\000jms1\@jms1.net\000not.my.real.password")'
# AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ=
Example of script:
nc smtp.server.org 587
220 smtp.server.org ESMTP Postfix ehlo griffin.hell 250-smtp.priorweb.be 250-PIPELINING 250-SIZE 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN {{{1}}} 250-ENHANCEDSTATUSCODES 250 8BITMIME AUTH PLAIN AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ= 235 2.7.0 Authentication successful mail from: jms1@jms1.net 250 2.1.0 Ok rcpt to: jms1@jms1.net 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> from: Jimmy <jms1@jms1.net> to: Jimmy <jms1@jms1.net> subject: test test . 250 ok 1311459496 qp 15928 quit 221 2.0.0 Bye
Note: EHLO is the more advanced helo command, that also lists the features supported by the server.
Expect script for testing SMTP
From [3]. Usage:
expect mail.exp smtp.server.org from@address.org to@address.org
The script (mail.exp):
#!/usr/bin/expect
set mailserver [lrange $argv 0 0]
set from [lrange $argv 1 1]
set to [lrange $argv 2 2]
spawn telnet $mailserver 25
expect "failed" {
send_user "$mailserver: connect failed\n"
exit
} "2?? *" {
} "4?? *" {
exit
} "refused" {
send_user "$mailserver: connect refused\n"
exit
} "closed" {
send_user "$mailserver: connect closed\n"
exit
} timeout {
send_user "$mailserver: connect to port 25 timeout\n"
exit
}
send "HELO foo.com\r"
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "MAIL FROM: <$from>\r"
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "RCPT TO: <$to>\r"
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "DATA\r"
expect "3?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "From: $from\r"
send "To: $to\r"
send "Subject: test\r"
send "This is a test message\r"
send ".\r"
expect "2?? *" {
} "5?? *" {
exit
} "4?? *" {
exit
}
send "QUIT\r"
exit
Bash script for testing SMTP
This uses the TCP/UDP devices available in Bash:
#! /bin/bash
#
# Usage: smtp.sh mail.server.org from@address.org to@address.org
MAILSERVER=$1
FROM=$2
TO=$3
exec 5<>/dev/tcp/${MAILSERVER}/25
cat <&5 &
sleep 1
echo -e "HELO dummy.domain" >&5
sleep 1
echo -e "MAIL FROM: $FROM" >&5
sleep 1
echo -e "RCPT TO: $TO" >&5
sleep 1
echo -e "DATA" >&5
sleep 1
echo -e "subject: test bash" >&5
echo -e "" >&5
echo -e "test bash" >&5
echo -e "." >&5
sleep 1
echo -e "QUIT" >&5
sleep 1