Unable to send a email through the command line on (Ubuntu Desktop)

Solution 1:

I routinely send email from within Ubuntu using the command line using mailx and gmail, perhaps this will be useful for you?

Create the file: $HOME/.mailrc by running:

touch $HOME/.mailrc

Then open this file with your favourite text editor and add the following:

#---------------------------#
# Setting mailx for gmail!! #
#---------------------------#
set smtp-use-starttls
set smtp-auth=login
set smtp=smtp://smtp.gmail.com:587
set from="[email protected]"
set [email protected]
set smtp-auth-password=your_gmail_password
set ssl-verify=ignore
set nss-config-dir=/etc/ssl/certs

Remember to use your own gmail username and password, and making sure you have installed the Ubuntu ca-certificates package. Then you can send email easily from the command line as follows:

echo "Testing, Testing, Testing" | mailx -s "My test..." [email protected]

The $HOME/.mailrc could easily be configured for other mail servers if you don't have a gmail account, but using gmail in this way means not having to bother with Postfix and friends.

Below is a test, demonstration email using a verbose setting, I have masked the email address as it is my own:

andrew@ilium~$ echo "Testing, Testing, Testing" | mailx -v -s "My test..." [email protected]
Resolving host smtp.gmail.com . . . done.
Connecting to 173.194.72.108:587 . . . connected.
220 smtp.gmail.com ESMTP u64sm18738348pfa.86 - gsmtp
>>> EHLO ilium.andrews-corner.org
250-smtp.gmail.com at your service, [203.158.63.248]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
>>> STARTTLS
220 2.0.0 Ready to start TLS
>>> EHLO ilium.andrews-corner.org
250-smtp.gmail.com at your service, [203.158.63.248]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
>>> AUTH LOGIN
334 VXNlcm5hbWU6
>>> YW5kcmV3LmRhdmlkLnN0cm9uZ0BnbWFpbC5jb20=
334 UGFzc3dvcmQ6
>>> Pz8lPTQyMDk1WnhpdXlxbQ==
235 2.7.0 Accepted
>>> MAIL FROM:<[email protected]>
250 2.1.0 OK u64sm18738348pfa.86 - gsmtp
>>> RCPT TO:<[email protected]>
250 2.1.5 OK u64sm18738348pfa.86 - gsmtp
>>> DATA
354  Go ahead u64sm18738348pfa.86 - gsmtp
>>> .
250 2.0.0 OK 1455275914 u64sm18738348pfa.86 - gsmtp
>>> QUIT
221 2.0.0 closing connection u64sm18738348pfa.86 - gsmtp
andrew@ilium~$ 

Pretty cool?