On 30/11/2012 7:14 PM, Robert Thorsby wrote:
> On 01/12/12 09:32:11, Chris Purves wrote:
>> > On Thu, 29 Nov 2012 21:39:32 -0400, Chris Purves wrote:
>> >> I'm having problems with the output of cron jobs.  cron sets the From
>> >> header as root, but does not include the domain.  My email is then
>> >> rejected because it doesn't include a proper email address in the
>> >>  From header.
> <snip>
>> It's because of the From header.  The envelope-from is fine.  The
>> message I receive is:
>> '550 No verifiable sender address in message headers'
>
> I've been sitting on the sidelines waiting for one of the msmtp gurus to
> give you the definitive answer.
>
> I have just looked up one of my ancient scripts that used msmtp to send
> attachments (msmtp was the easiest lightweight way to do so from a script).
>
> First, don't ask cron to do too much -- it doesn't like it. Just point
> cron at a shell script.
>
> The rest is done in your shell script (or whatever).
>
> Secondly, create a dummy msmtp runcontrol file with one section
> [Default]. Give the dummy file 600 permissions. Delete it at the end of
> the script.
>
> Thirdly, at the commencement of your message create a few additional
> headers [Date, From, Sender, Reply-To, Message-ID, etc.], being careful
> to have no blank lines before or between the additional headers and one
> blank line after them.
>
> Then have your script execute:
>
> msmtp --file=/tmp/dummy/msmtp/runcontrol/file -- "recipient" < "$MESSAGE"
>
> Because msmtp is a well behaved MTA it works out that the first part of
> the message is additional headers and treats them accordingly. I found,
> and still do find, that the combination of all the header information
> and the "additional" headers at the beginning of the message works for me.
>

Robert,

Thanks for the input.  I didn't implement it exactly as you suggested, 
but I made an msmtp wrapper that adds the domain to the From header if 
it doesn't already include one.  I found that cron uses 
/usr/sbin/sendmail which for me is a link to msmtp.  I replaced the link 
with the following script:

#!/bin/bash
#this replaces /usr/sbin/sendmail and adds domain to from address

tmpfile="/tmp/mailbody$RANDOM"
msmtp_path="/usr/bin/msmtp"

touch $tmpfile

cat - |
while read line
do
   if [[ "$line" =~ ^From && "$line" =~ ^[^@]*$ ]]
   then
     line=`echo $line | sed 's/\(From: *[^ ]*\)/\[email protected]/'`
   fi
   echo $line >> $tmpfile
done

cat $tmpfile | $msmtp_path $@
rm $tmpfile


-- 
Chris Purves
Visit my blog: http://chris.northfolk.ca

"It's not the end of the world, but you can see it from there." - Pierre 
Trudeau

------------------------------------------------------------------------------
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net
_______________________________________________
msmtp-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/msmtp-users

Reply via email to