When I run:

echo "Subject: mysubject\n\nmytext" | sudo ssmtp myemail@gmail.com

I expect the line above to send an email to myemail@gmail.com with mysubject as Subject, and mytext as body of the email.

However, it sends an email with mysubject\n\nmytext as Subject.

sudo ssmtp myemail@gmail.com <<<$"Subject: TESTING\n\nBody: of the email. TEST." has the same problem (that is, packages the whole text as Subject.)

What's wrong? The lines above seem to work for others.

  • Not familure with ssmtp, but had a similar issue with sendemail (note the E). Had to convert subject and body with Base64 to get new lines through. Dont forget to set the Content-Transfer-Encoding: base64. – jc__ Apr 30 '18 at 13:36
  • echo does not do anything special with \n unless (wildly unportable) flags are strewn into to the mix. Try instead printf(1) or better yet use mail(1) or mutt(1). – thrig Apr 30 '18 at 13:57
  • @thrig: printf "Subject: mysubject\n\nmytext" | sudo ssmtp myemail@gmail.com instead of echo ... works. Thanks – Pierre B Apr 30 '18 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.