Sending Mail on Linux via Bash/Command line

0

1

I'm currently trying to send mails via bash script on Linux. I searched the internet and found this code:

echo "This is my body" | mail -s"this is my header" thisis@my.mail

I don't get any response either in the bash script nor when I type it directly in the command line. I waited for at least 3 hours now and still got no mail.

I just found that the log says stat=Deferred: Connection timed out with backup-mx.mcs.de. when sending to my Mail address but also has some entries with to<www-data@server.de> and stat=Sent

Fanvaron

Posted 2013-10-24T12:36:38.730

Reputation: 1

You need to configure mail on your machine before you can expect it to work. Particularly, you'll need to configure your machine to forward Internet mail to your ISP's mail server. – David Schwartz – 2013-10-24T15:56:01.393

Ohh, ok, I didn't know that most internet sources say it works out of the box – Fanvaron – 2013-10-24T15:57:37.797

How would it know where to send the mail? There's no "mail server discovery" protocol. – David Schwartz – 2013-10-24T16:00:22.077

Answers

1

The command—in and of itself—you are showing as an example is correct will work:

echo "This is my body" | mail -s"this is my header" thisis@my.mail

But you need to have some kind of local MTA (mail transfer agent) installed on the Linux machine you are attempting to do this on before it can work. On Ubuntu setting this up is as simple as installing Postfix and some related mail utilities like this:

sudo aptitude install postfix mailutils

Then after that is installed your mail command—as well as others—should work on the command line of that Linux server.

JakeGould

Posted 2013-10-24T12:36:38.730

Reputation: 38 217

0

You can try mutt command as follows according to this site:

echo "<message body>" | mutt -s "<subject>" -a "<optional attachment>" -e "my_hdr From:<from address>" -- <recipients list separated by space>

Sadupa Wijeratne

Posted 2013-10-24T12:36:38.730

Reputation: 1