8

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 my@email.com < /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.

josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157

1 Answers1

11

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@address.com <<EOF
subject:This is a test
from:from@address.com
Body message here...
EOF
Flexo
  • 87,323
  • 22
  • 191
  • 272
josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157