Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sendmail from command line [closed]

I'm trying to write a bash script, to be run by a cron task, which will send me an email under certain circumstances.

In order to try and get sendmail working with my Sendgrid SMTP settings, I've edited the /etc/postfix/main.cf file with the following:

smtp_sasl_password_maps = static:<username>:<password>
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
smtp_tls_security_level=encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

I restarted postfix using sudo /etc/init.d/postfix restart

And tried sending an email from the command line using the following command:

sendmail [email protected] < /tmp/email.txt

This results in the following output:

You have new mail in /var/mail/ubuntu

Why isn't sendgrid sending with my email using the Sendgrid SMTP details I specified in main.cf?

Please note, this question relates to sendmail only, I don't want to install other SMTP clients and apps, it needs to work as is.

like image 532
josef.van.niekerk Avatar asked May 09 '13 08:05

josef.van.niekerk


1 Answers

My Postfix configuration was wrong. I needed to use the following:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:<username>:<password>
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

Sending the email via bash script is done as follows:

sendmail [email protected] <<EOF
subject:This is a test
from:[email protected]
Body message here...
EOF
like image 176
josef.van.niekerk Avatar answered Oct 18 '22 11:10

josef.van.niekerk