I'm trying to use SMTP to send mail to my account on some server (say, on Gmail).
So far I've tried:
220 mx.google.com ESMTP y14sm3079810ibf.45
HELO
250 mx.google.com at your service
STARTTLS
220 2.0.0 Ready to start TLS
AUTH LOGIN
Connection closed by foreign host.
What am I doing wrong, and how can I fix it so I send an email as though I were my own server?
Just submitting the
STARTTLS
command doesn't put the connection into TLS mode. You have to negotiate and implement it properly.Gmail requires TLS to relay mail on your behalf. This type of connection is necessary when your desktop or mobile e-mail client is sending mail from your Gmail account.
However, any normal mail server will still accept a message to a recipient on that server without using TLS or any kind of authentication. For example, you can connect to
gmail-smtp-in.l.google.com
on port 25 and conduct an unencrypted SMTP session.Assuming that you are [email protected], you are logged into your mail server mail.mydomain.com, and you are sending a message to [email protected], it looks like this:
dig yourdomain.com mx
and note the results (let's say it's mail001.yourdomain.com)telnet mail001.yourdomain.com 25
Caveats:
To learn more, see the Wikipedia article.
You issued the
HELO
command to your SMTP server. This tells it that you want to use the original SMTP commands.STARTTLS
is not one of these commands, thus you should not be able to useSTARTTLS
.The first step in resolving this is to switch from the
HELO
command to theEHLO
command. When you do, you will see that the SMTP server responds with the set of SMTP extensions that it supports. Hopefully,STARTTLS
will be listed.Here's a conversation with GMail's SMTP server: