SMTP: Difference between revisions
Jump to navigation
Jump to search
Line 74: | Line 74: | ||
Note: '''EHLO''' is the more advanced helo command, that also lists the features supported by the server. |
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> |
Revision as of 22:57, 23 July 2011
Testing SMTP
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
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