Ubuntu: Why can't I send emails from the command line to my gmail account


I'm using the command:

echo "Test if email can be sent from server" | mail -s "Test" myaccount@gmail.com

This is on an Ubuntu Server 12.04 completely up to date.

To catch you up on my troubleshooting:

1) I have installed mailutils with the "Internet Site" option (or whatever that internet option was; I can't remember exactly what it was called off the top of my head).

2) I have added myself to the group 'mail'.

3) I have checked that my ISP does, in fact, block port 25. I followed these instructions using port 587, which is unblocked (I'm not sure that this has an effect on outgoing mail; it looks like a mail server to me)

4) I've also tried echo "Test if email can be sent from server" | sendmail -f myaccount@gmail.com myaccount@gmail.com, but this also appears to do nothing.

5) I am worried that gmail is receiving on port 587, but that it doesn't know what to do with the traffic. Is this an unfounded consideration?

6) My gmail user name contains a '.' before the '@gmail.com'. Is it possible that this is confusing the mail and sendmail commands? (edit: after some more experimenting, this is probably not the problem)


SMTP servers only accept incoming mail on TCP port 25. If they accept mail from other ports such as the submission port 587, that is only for the submission of new mail from known/authenticated clients sending mail. Incoming mail from an unknown client should only be accepted on port 25.

If your ISP is blocking outgoing connections on port 25 you will need to either

  • have them remove this block
  • relay the mail to a mail relay outside your local network which considers you a trusted client and let the relay forward it on. Speak to this relay on port 587.
  • authenticate as a client on the destination server using port 587 so the destination thinks of you as an authenticated client. I don't know if gmail allows this because the normal way they accept mail from clients is via web or their proprietary apps.

Edit: the OP pointed out in a commend that Gmail allows you to authenticate and submit mail by SMTP at smtp.gmail.com on port 465 (SMTP over SSL).

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »