flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.79k stars 366 forks source link

Reject emails with wrong address (relay emails) #172

Closed lord-alfred closed 5 years ago

lord-alfred commented 5 years ago

I connected the MX record and set the server IP address with guerrilla. But I did not include the domain in the settings (I did not add it to the list allowed_hosts). I decided to try to see how guerrilla would reject such letters. And I'm a little confused: why, after response "454 ... Relay access denied ..." from guerrialla, did the sending server still send command "DATA"? Is this normal or could there be an error in guerrialla somewhere? Why get the body of the letter if it has already been rejected anyway?

Logs:

time="2019-08-14T21:10:57+03:00" level=info msg="Handle client [XX.140.190.XX], id: 5"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n220 mx.test.com SMTP #5 (1) 2019-08-14T21:10:57+03:00\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: EHLO forward104o.mail.yandex.net"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250-mx.test.com Hello\r\n250-SIZE 3145728\r\n250-PIPELINING\r\n250-STARTTLS\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: STARTTLS"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n220 2.0.0 Ready to start TLS\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: EHLO forward104o.mail.yandex.net"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250-mx.test.com Hello\r\n250-SIZE 3145728\r\n250-PIPELINING\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: MAIL FROM:<test-sender@yandex.ru>"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: RCPT TO:<test-recipient@test.com>"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n454 4.1.1 Error: Relay access denied: test.com\r\n"
time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: DATA"
time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n503 5.5.1 Error: No recipients\r\n"
time="2019-08-14T21:10:58+03:00" level=debug msg="Client sent: RSET"
time="2019-08-14T21:10:58+03:00" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n"
time="2019-08-14T21:10:58+03:00" level=debug msg="Client sent: QUIT"
time="2019-08-14T21:10:58+03:00" level=debug msg="Writing response to client: \n221 2.0.0 Bye\r\n"
flashmob commented 5 years ago

Most likely the sender is sending using 'pipelining', which means their transaction goes through the socket in one go, without waiting for a reply. They just read the reply as it comes through the other side. Most likely the sender sent everything so fast that they didn't get a chance to read and parae the reply yet.

On Thu., 15 Aug. 2019, 03:19 Lord Alfred, notifications@github.com wrote:

I connected the MX record and set the server address with guerrilla. But I did not include the domain in the settings (I did not add it to the list allowed_hosts). I decided to try to see how guerrilla would reject such letters. And I'm a little confused: why, after response "454 ... Relay access denied ..." from guerrialla, did the sending server still send command "DATA"? Is this normal or could there be an error in guerrialla somewhere? Why get the body of the letter if it has already been rejected anyway?

Logs:

time="2019-08-14T21:10:57+03:00" level=info msg="Handle client [XX.140.190.XX], id: 5" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n220 mx.test.com SMTP #5 (1) 2019-08-14T21:10:57+03:00\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: EHLO forward104o.mail.yandex.net" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250-mx.test.com Hello\r\n250-SIZE 3145728\r\n250-PIPELINING\r\n250-STARTTLS\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: STARTTLS" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n220 2.0.0 Ready to start TLS\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: EHLO forward104o.mail.yandex.net" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250-mx.test.com Hello\r\n250-SIZE 3145728\r\n250-PIPELINING\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: MAIL FROM:test-sender@yandex.ru" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: RCPT TO:test-recipient@test.com" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n454 4.1.1 Error: Relay access denied: test.com\r\n" time="2019-08-14T21:10:57+03:00" level=debug msg="Client sent: DATA" time="2019-08-14T21:10:57+03:00" level=debug msg="Writing response to client: \n503 5.5.1 Error: No recipients\r\n" time="2019-08-14T21:10:58+03:00" level=debug msg="Client sent: RSET" time="2019-08-14T21:10:58+03:00" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n" time="2019-08-14T21:10:58+03:00" level=debug msg="Client sent: QUIT" time="2019-08-14T21:10:58+03:00" level=debug msg="Writing response to client: \n221 2.0.0 Bye\r\n"

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/172?email_source=notifications&email_token=AAE6MP5MIEF3MR3I2WCAE6TQEREDJA5CNFSM4ILXTLJ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFIXNUQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MP5ZRSE67JDHBCDPBK3QEREDJANCNFSM4ILXTLJQ .

lord-alfred commented 5 years ago

Maybe for this relay emails just need to close/disconnect after send "454 4.1.1 Error: Relay access denied"?

flashmob commented 5 years ago

No, because the client can add up to 100 recipients per transaction. They may have 1 or more addresses wrong, but other may be right. Note that 4xx error messages are classed as persistent transient failure

lord-alfred commented 5 years ago

Thank! Now I understand everything :)