Send email using mail hangs - Ubuntu 14.04

0

I have try to send email using ubuntu shell and when I execute the below, session is getting hanged. Kindly help me on this.

echo "hello world" | mail -s "a subject" abc@gmail.com

After some time below message is throwing from the terminal.

mail: cannot send message: Process exited with a non-zero status

Daz

Posted 2016-07-26T10:39:42.203

Reputation: 63

post the output of echo "hello world" | mail -v -s "a subject" abc@gmail.com (notice the -v after mail). – rafalmp – 2016-07-26T17:58:15.850

echo "hello world" | mail -V -s "a subject" dasith9@gmail.com mail (GNU Mailutils) 2.99.98 Copyright (C) 2010 Free Software Foundation, inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. – Daz – 2016-07-27T09:59:38.600

No, it has to be -v not -V, small letter 'v' not capital one: – rafalmp – 2016-07-27T11:15:24.053

thanks for the support. This is what I am getting mail: invalid option -- 'v' Try 'mail --help' or 'mail --usage' for more information. – Daz – 2016-07-28T04:29:43.553

ok one more time - the whole command as it should be entered in terminal: echo "hello world" | mail -v -s "a subject" dasith9@gmail.com mail – rafalmp – 2016-07-28T09:24:13.207

Still Same :(

mail: invalid option -- 'v' Try 'mail --help' or 'mail --usage' for more information. – Daz – 2016-07-28T09:27:45.377

Ah sorry my bad, gnu mail has no 'verbose' option... You can insert the line set verbose in your ~/.mailrc (create it if does not exist) then delivery details will be printed on screen - there should be some helpful information. – rafalmp – 2016-07-28T09:47:32.173

I have just add set verbose using vi. Still same. Can you guide me on this :( – Daz – 2016-07-28T09:51:41.013

Answers

1

To diagnose why mail fails, try the following:

  • open ~/.mailrc in your editor
  • make sure it contains line set verbose
  • save and exit
  • try echo "hello world" | mail -s "a subject" your@addres.com

You should see detailed output - mine looks like this:

root@vagrant-ubuntu-trusty-64:~# echo "test" | mail -s "test" rafal@(...)
WARNING: local host name (vagrant-ubuntu-trusty-64) is not qualified; see cf/README: WHO AM I?
rafal@(...)... Connecting to [127.0.0.1] via relay...
220 vagrant-ubuntu-trusty-64 ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1; Thu, 28 Jul 2016 10:43:54 GMT; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
>>> EHLO vagrant-ubuntu-trusty-64
250-vagrant-ubuntu-trusty-64 Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<vagrant@vagrant-ubuntu-trusty-64> SIZE=209  AUTH=vagrant@vagrant-ubuntu-trusty-64
250 2.1.0 <vagrant@vagrant-ubuntu-trusty-64>... Sender ok
>>> RCPT To:<rafal@(...)>
>>> DATA
250 2.1.5 <rafal@(...)>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
050 <rafal@(...)>... Connecting to (...). via esmtp...
050 220 (...) ESMTP Postfix (Debian/GNU)
050 >>> EHLO vagrant-ubuntu-trusty-64
050 250-(...)
050 250-PIPELINING
050 250-SIZE 10240000
050 250-VRFY
050 250-ETRN
050 250-STARTTLS
050 250-AUTH PLAIN LOGIN
050 250-ENHANCEDSTATUSCODES
050 250-8BITMIME
050 250 DSN
050 >>> STARTTLS
050 220 2.0.0 Ready to start TLS
050 >>> EHLO vagrant-ubuntu-trusty-64
050 250-(...)
050 250-PIPELINING
050 250-SIZE 10240000
050 250-VRFY
050 250-ETRN
050 250-AUTH PLAIN LOGIN
050 250-ENHANCEDSTATUSCODES
050 250-8BITMIME
050 250 DSN
050 >>> MAIL From:<vagrant@vagrant-ubuntu-trusty-64> SIZE=467 AUTH=<>
050 250 2.1.0 Ok
050 >>> RCPT To:<rafal@(...)>
050 >>> DATA
050 504 5.5.2 <vagrant-ubuntu-trusty-64>: Helo command rejected: need fully-qualified hostname
050 554 5.5.1 Error: no valid recipients
050 >>> RSET
050 250 2.0.0 Ok
050 <vagrant@vagrant-ubuntu-trusty-64>... Connecting to local...
050 <vagrant@vagrant-ubuntu-trusty-64>... Sent
250 2.0.0 u6SAhslg010491 Message accepted for delivery
rafal@(...)... Sent (u6SAhslg010491 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 vagrant-ubuntu-trusty-64 closing connection

look for any errors - in my case there were these two lines:

050 504 5.5.2 <vagrant-ubuntu-trusty-64>: Helo command rejected: need fully-qualified hostname
050 554 5.5.1 Error: no valid recipients

so the mail was rejected because my host does not have a fully-qualified hostname.

edit: you can also check /var/log/mail.log/ and /var/mail/<yourusername> if there is any useful information about errors.

rafalmp

Posted 2016-07-26T10:39:42.203

Reputation: 376

This is my mailrc

root@dig:/# cat ~/.mailrc set verbose root@dig:/#

After adding the above I have executed the below

echo "hello world" | mail -v -s "a subject" dxxx@abc.com

I got the below error

root@diginapp-preprodction:/# echo "hello world" | mail -v -s "a subject" dasitha@duosoftware.com mail: invalid option -- 'v' Try 'mail --help' or 'mail --usage' for more information. root@dig:/# cat ~/.mailrc set verbose root@dig:/# – Daz – 2016-07-28T12:35:39.007

Sorry my bad again, try without -v: echo "hello world" | mail -s "a subject" your@addres.com - amended my answer. – rafalmp – 2016-07-28T13:03:00.507

This is what I am getting.

mail: sendmail (/usr/sbin/sendmailn mail: mu_mailer_send_message(): using From: root@diginapp-preprodction.c.digin-preproduction.internal mail: exec /usr/sbin/sendmail argv: /usr/sbin/sendmail -oi -f root@diginapp-preprodction.c.digin-preproduction.internal -t mail: Sending headers... mail: Header: Subject: a subject mail: mail: Header: To: <dasitha@duosoftware.com> mail: mail: Header: X-Mailer: mail (GNU Mailutils 2.99.98) mail: mail: Header: mail: mail: Sending body... mail: /usr/sbin/sendmail exited with: 0 mail: – Daz – 2016-07-28T14:56:26.867