17

I've got msmtp setup on Ubuntu 10.10 so that cron can send me emails. That works like a champ, for the most part.

However, emails coming to my gmail account show up as coming from (unknown sender), and the headers show:

From: root (Cron Daemon)

How can I set the From header to a valid email address?

I've just got msmtp symlinked as /usr/sbin/sendmail

The one possible solution I've found is here: http://tech.bluesmoon.info/2010/01/pretty-print-cron-emails.html

However, I'm curious if there's a simpler way.

Jason Navarrete
  • 343
  • 3
  • 7
  • I'm having the same issue and can't find any good solution. Did anyone come up with an elegant solution to this? – Andrew S Jan 23 '17 at 17:21
  • 1
    I ended up going to exim so I had a little more control over what was going on. – Jason Navarrete Jan 24 '17 at 21:02
  • 1
    See related questions : [How to customise email headers from Vixie-cron (debian) and msmtp?](https://serverfault.com/questions/438843) ; [How to change “From:” field for emails from Cron?](https://serverfault.com/questions/121121) – Max Apr 24 '19 at 14:10

3 Answers3

10

I've found two solutions:

  • With msmtp 1.8.8 or later (appeared in Ubuntu 20.10), use the set_from_header on configuration setting, which can override the existing From: unlike the earlier add_missing_from_header which could only add it when missing
  • With earlier versions (e.g. Ubuntu 20.04),
    • remove the msmtp-mta package, now useless,
    • create a two-line script rewriting the header, e.g. /usr/local/bin/msmtp-pseudo-mta.bash
#!/bin/bash
# Workaround until mtmsp >= 1.8.8 in Ubuntu 20.10.
sed -e "s/From: root (Cron Daemon)/From: WHATEVER YOU LIKE/" | msmtp $BASH_ARGV
    • make it executable, e.g. chmod 755 /usr/local/bin/msmtp-pseudo-mta.bash
    • symlink it as sendmail:
sudo ln -s /usr/local/bin/msmtp-pseudo-mta.bash /usr/sbin/sendmail

Idea from: https://serverfault.com/a/441414/17379

FGM
  • 201
  • 2
  • 5
1

No problem. Just configure it like mentioned in the manual: http://msmtp.sourceforge.net/doc/msmtp.html#Envelope_002dfrom-address

maildomain example.com

should add example.com to all mails without domain set.

mailq
  • 16,882
  • 2
  • 36
  • 66
  • This only allows me to set the from email based on the user. It doesn't set the actual header that gmail reads. Currently I'm specifying the from address in the msmtprc. Without a valid from email, it keeps all my cron emails to spam, and I have to explicitly override it with a filter. – Jason Navarrete Oct 13 '11 at 19:16
0

You can use -a switch in order to specify additional headers. And an additional header can be From, so it's just what you need.

Example:

/some_command.sh | mail -s "Email subject" -a "From:Sender Name <sender@email.com>" recipient@email.com
Sinklar
  • 93
  • 1
  • 6