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.

Oskar K.
  • 295
  • 2
  • 4
  • 16
  • 1
    Possible duplicate of [How to send mail from the command line?](http://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line) – Terrance Feb 12 '16 at 05: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 05: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 05:53
  • @fkraiem, where is it? – Oskar K. Feb 12 '16 at 08:54
  • In `/var/log` like all other logs. ;) – fkraiem Feb 12 '16 at 08:55
  • @fkraiem, it says "open /etc/postfix/main.cf: No such file or directory" – Oskar K. Feb 12 '16 at 08:59
  • So you have installed Postfix? How did you install it? If you only want to be able to send email through an external SMTP server (such as the one provided by your ISP), you can install `ssmtp`, which is much easier to configure. – fkraiem Feb 12 '16 at 09:01
  • are you tring to send email to remote server(like gmail)? do you have Internet on your local machine? – koolwithk Feb 12 '16 at 09:02
  • @editinit, to a remote address. – Oskar K. Feb 12 '16 at 09:03

1 Answers1

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?

andrew.46
  • 37,085
  • 25
  • 149
  • 228