4

I'm trying to send a email from my Ubuntu:

 mailx -s "This is all she wrote" < /dev/null something@fdsfds.com
 or
 mail -s "hfdsfds" something@fdsfds.com

And nothing has happened at all. No email. Why not?

Is it matters, it's my local computer, not a remote server.

9
  • 1
    Possible duplicate of How to send mail from the command line? – Terrance Feb 12 '16 at 5:18
  • Cannot suggest how to solve this, but i personally use mutt from time to time. An easy to configure app. Might need to search the interwebs on how to configure it for a bit. Let me know if you want to see my config – Sergiy Kolodyazhnyy Feb 12 '16 at 5:48
  • 1
    Obviously not a duplicate, as the answers to that other question do not say what do to in case of errors. What are the contents of mail.log (and possibly also mail.err)? – fkraiem Feb 12 '16 at 5:53
  • @fkraiem, where is it? – Oskar K. Feb 12 '16 at 8:54
  • In /var/log like all other logs. ;) – fkraiem Feb 12 '16 at 8:55
7

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="your_gmail_username@gmail.com"
set smtp-auth-user=your_gmail_usernameg@gmail.com
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..." someone@whatever.com

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..." xxx@gmail.com
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:<xxx@gmail.com>
250 2.1.0 OK u64sm18738348pfa.86 - gsmtp
>>> RCPT TO:<xxx@gmail.com>
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.