SMTP: Remote client not responding to 220 - sockets

Recently I've been experimenting with a simple script that listens on port 25, and receives and logs any incoming emails.
It's a very primitive script, and it doesn't implement the SMTP protocol at all. It just simply spits out canned replies, and it works something like this:
Wait for an incoming socket.
Send "220 example.com ESMTP Postfix".
Receive one line, typically like "EHLO other.com".
Send "250 example.com, I am pleased to meet you".
Receive lines until "DATA", reply with "250 Ok" every time".
Send "354 End data with .".
Receive lines until "." is received.
Send 250 Ok: queued as 12345.
Receive any final lines then close the socket.
(example.com is in place of my real domain's FQDN.)
It's a very crude script indeed; however, for the past few months it's worked perfectly for every email that I needed to receive. I can receive fine from Gmail, Protonmail, verification emails, etc. I also caught some internet-wide scans, so it serves as a fun honeypot too.
Today, I tried to receive a Microsoft account verification email to register a Microsoft account. The remote client didn't seem to respond to the 220 at all!
# nc -l -v -p 25
Listening on [0.0.0.0] (family 0, port 25)
Connection from mail-co1nam03on0003.outbound.protection.outlook.com 56725 received!
220 example.com ESMTP Postfix
No matter what I tried, the client wouldn't send anything. What am I doing wrong? Any ideas are welcome.

tripleee solved this in the comments, so I'm posting it as an answer here for everyone to see. The problem is that I was giving just LF as a newline, not CRLF. So I replaced all the '\n' with '\r\n' in my code, and that fixed it. I guess the other mailservers were just being lenient with me.

Related

Can't stablish SMTP connection with Yahoo, I think the TCP handshake is failing

I'm trying to stablish a SMTP connection with hotmail or yahoo (both giving the same issue). They connect to my server (192.168.1.220) on port 25 and I send the 220 confirmation, but they don't reply with HELO, EHLO nor anything.
So I scanned the packages and I found this:
http://i.stack.imgur.com/Kj4r0.jpg
As far as I see, SYN is sent without any problems, SYN-ACK works right, then ACK doesn't reply with the right Seq value (it should be 2, right?).
Do you know what could be causing the connection issue? Should I try UDP or nothing here is wrong and I am misunderstanding the whole situation?
Thank you very much!
The problem wasn't here.
We were sending our 220 message just with \n and no \r. So we sent "220 Hello\n\r" and it worked.

Yahoo and Hotmail won't reply HELO/EHLO to my SMTP server

I've been looking for an answer to this all over the internet, and sadly I've come nowhere near one.
Today I decided to write a SMTP server for sending/recieving emails from my RPi. I wanted to do it from scratch, so switching to Postfix is not an option. I've wrote my code on Java and all the connections are handled with sockets.
My server works like -as I understood- most SMTP servers work:
- Email sender connets to my server on port 25.
- I say "220 Hello, welcome to my server"
- They then reply HELO or EHLO and so the communication goes on.
This has worked great so far with GMail, some anonymous email sending websites, mail.com, etc, but I can't make it work with Hotmail and Yahoo. They connect, I send them the "220 Hello, etc" line, but they don't reply HELO nor EHLO nor anything at all.
Yahoo has been trying to connect for a while now, but they don't reply anything at all. Neither does, again, Hotmail.
Do you know if they work in some special way, if I am messing something up with the protocol, or what could be happening?
Thank you very much.
EDIT
Some other things:
- I'm using a No-ip address.
- I'm listening to ports 25, 465 and 587, and all of them have been opened in my router.
Make sure your lines end with \r\n and not just \n.

PHPMailer EHLO Error

I have a problem for a couple of days ago me going crazy, I have a script that sends mails using phpMailer and arsys.
The fact is that the overnight stops working, check the code and seems fine, it's more, it works correctly if I run it from the test server that comes through another IP.
I found that the server was not on any spam blackList and found the reference to be to a PBL, me worry about removing it from there.
Anyway, I still can not send mail from that server and both my other test script I programmed work correctly on development server but not on the production server.
The error that is specifically this
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> ERROR: HELO not accepted from server: 220 ESMTP Postfix smtp-04.servidoresdns.net
SMTP -> ERROR: AUTH not accepted from server: 250-250-llsg993-a04.servidoresdns.net PIPELINING 250-SIZE 51200000 250-ETRN 250-250-STARTTLS AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN 250-AUTH = DIGEST MD5 CRAM-MD5 LOGIN PLAIN 250-250 8BITMIME ENHANCEDSTATUSCODES
It says it can not authenticate the credentials are fine but since the same script from another server goes perfectly.
Also came through a tcptraceroute to port 25 SMTP server.
Only strange thing I see is that when running
tcptraceroute p 25 smtp.miservidor.com
He says:
Sorry, Local Requested port is already in use. Use P, instead of p, to override.
But after using P instead of p and functions
Anyone shed me some light on this?
Who may be filtering my IP address ??
It's very common for ISPs to block outbound connections to port 25 by default. Try using SMTPSecure = 'tls' and Port = 587 - that server definitely responds on that port.
Connection problems are covered in the PHPMailer docs.
I noticed that never answered this question, the problem was the time, the function did not have enough time to contact with server. I increased the time in phpMailer class and everything went back to work.

Send mail via CMD console

Hi i want to send mail via microsoft cmd console. I tried many way, but i didnt succeed.
i tried this article http://jpsoft.com/help/index.htm?sendmail.htm
sendmail "bob#bob.com bcc:joe#joe.com" Test Hello!
the error is :
'sendmail' is not recognized as an internal or external command operable program or batch file
and
this article : http://www.brighthub.com/office/collaboration/articles/21840.aspx#imgn_1
c:\>"c:\program files\microsoft office\office12\outlook.exe" /c ipm.note /m someone#gmail.com /a "c:\logs\logfile.txt"
the error is :
the process can not access the file because it is being used by another proccess
but it didnt worked. i dont know where is the problem or what is the problem.
thanks for your advice.
Scenario:
Your domain: mydomain.com
Domain you wish to send to: theirdomain.com
1. Determine the mail server you're sending to.
Open a CMD prompt
Type
NSLOOKUP
set q=mx
theirdomain.com
Response:
Non-authoritative answer:
theirdomain.com MX preference = 50, mail exchanger = mail.theirdomain.com
Nslookup_big
EDIT
Be sure to type exit to terminate NSLOOKUP.
2. Connect to their mail server
SMTP communicates over port 25. We will now try to use TELNET to connect to their mail server "mail.theirdomain.com"
Open a CMD prompt
TELNET MAIL.THEIRDOMAIN.COM 25
You should see something like this as a response:
220 mx.google.com ESMTP 6si6253627yxg.6
Be aware that different servers will come up with different greetings but you should get SOMETHING. If nothing comes up at this point there are 2 possible problems. Port 25 is being blocked at your firewall, or their server is not responding. Try a different domain, if that works then it's not you.
3. Send an Email
Now, use simple SMTP commands to send a test email. This is very important, you CANNOT use the backspace key, it will work onscreen but not be interpreted correctly. You have to type these commands perfectly.
ehlo mydomain.com
mail from:<martin9700#mydomain.com>
rcpt to:<recipient#theirdomain.com>
data
This is a test, please do not respond
.
quit
So, what does that all mean?
EHLO - introduce yourself to the mail server HELO can also be used but EHLO tells the server to use the extended command set (not that we're using that).
MAIL FROM - who's sending the email. Make sure to place this is the greater than/less than brackets as many email servers will require this (Postini).
RCPT TO - who you're sending it to. Again you need to use the brackets. See Step #4 on how to test relaying mail!
DATA - tells the SMTP server that what follows is the body of your email. Make sure to hit "Enter" at the end.
. - the period alone on the line tells the SMTP server you're all done with the data portion and it's clear to send the email.
quit - exits the TELNET session.
4. Test SMTP relay
Testing SMTP relay is very easy, and simply requires a small change to the above commands. See below:
ehlo mydomain.com
mail from:<martin9700#mydomain.com>
rcpt to:<recipient#someotherdomain.com>
data
This is a test, please do not respond
.
quit
See the difference? On the RCPT TO line, we're sending to a domain that is not controlled by the SMTP server we're sending to. You will get an immediate error is SMTP relay is turned off. If you're able to continue and send an email, then relay is allowed by that server.
Unless you want to talk to an SMTP server directly via telnet you'd use commandline mailers like blat:
blat -to you#example.com -f me#example.net -s "mail subject" ^
-server smtp.example.net -body "message text"
or bmail:
bmail -s smtp.example.net -t you#example.com -f me#example.net -h ^
-a "mail subject" -b "message text"
You could also write your own mailer in VBScript or PowerShell.
From Linux you can use 'swaks' which is available as an official packages on many distros including Debian/Ubuntu and Redhat/CentOS on EPEL:
swaks -f you#example.net -t someone#example.com \
--server mail.example.com
A couple more command-line mailer programs:
mailsend
Mail Alert Simple Mailer
Both support SSL too.

Send email using Telnet

I found this article which explains sending email from telnet
http://www.kongtechnology.com/2008/01/27/smtp-authentication-and-send-emails-using-telnet/
but actually I have problem with it.
when i wrote this command
auth login
I got
Connection to host lost.
so, what is the problem?
http://www.ionfish.org/mxlookup
Type the URL of the site you want to find's mail server.
Open CMD, type:
telnet mx.sitedomain.com 25
then
HELO mx.sitedomain.com
next
MAIL FROM: president#whitehouse.gov
then
RCPT TO: secretary#whitehouse.gov
finally
SUBJECT: This message was brought to you in part by the moon.
Note: You need to send authentication requests, because most mail servers do not allow anonymous unsolicited mail to be sent. (spam).
http://technet.microsoft.com/en-us/library/aa995718%28v=exchg.65%29.aspx