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

5,648

Solution 1

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).

Solution 2

You must change the gmail security settings at https://myaccount.google.com/, by activating "Less secure app access". if "Less secure app access" is off, all emails that you send will be blocked by Google.

and next step, you can see at https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp

Share:
5,648

Related videos on Youtube

jaredad7
Author by

jaredad7

I am currently a cyber engineering/computer science student at Louisiana Tech University. My first language was C++, and I have done schoolwork in Java, sh shell scripting, python, and c. In addition, I know a (very) little HTML and CSS. I am interested in artificial intelligence, ubiquitous computing, and robotics research, and plan to work in the robotics and/or ubiquitous computing fields once I graduate. I eventually plan to teach computer science or cyber engineering on the university level. Learn more about me at http://web.jdembrun.com:4352/about.html

Updated on September 18, 2022

Comments

  • jaredad7
    jaredad7 over 1 year

    I'm using the command:

    echo "Test if email can be sent from server" | mail -s "Test" [email protected]

    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 [email protected] [email protected], 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)

    • mchid
      mchid almost 10 years
      If the "." is causing a problem you can usually use quotations in the command to show it is part of the name like this . . . "[email protected]"
    • jaredad7
      jaredad7 almost 10 years
      @mchid the quotes didn't help.
  • jaredad7
    jaredad7 almost 10 years
    How would I go about registering with a mail relay as a trusted client?
  • jaredad7
    jaredad7 almost 10 years
    It turns out that you can use a relay at smtp.gmail.com:465. This works perfectly.