A few people have emailed me asking me to integrate the perl code snippet into I wrote to strip illegal headers when sending email via Amazon SES into something actually usable. I’ve done so! I haven’t really tested this beyond sending some test emails, but here it is. Use this at your own risk, I make no warranty, blah blah blah.
This fix requires editing ses-send-email.pl
, so I’d advise making a backup copy, though I imagine you can always get a fresh version from Amazon if necessary.
Open ses-send-email.pl in a text editor and find the read_message
method. It should look like this:
https://gist.github.com/1120804.js?file=ses-send-email.pl
Delete that and paste this in its place:
https://gist.github.com/1120804.js?file=evan-ses-send-email.pl
I tried it on the command line and it gave the output I expected – I haven’t tried integrating it with sendmail/postfix since I haven’t encountered this problem. Here’s the test message I attempted to send:
From: evan@example.com To: evan@example.com Subject: Email Chicken: yummy Cats: yucky X-Zombies: kill them! Now we're out of the header, into the body. Grand!
From
, To
, and Subject
are required headers. Chicken
& Cats
are illegal, X-Zombies
should be ok since it’s X-ified. Here’s what happened when I tried to send with the unmodified ses-send-email.pl:
[Tue Aug 02 14:14:51 evan@EvanMBP 62 amazon-email]$ ./ses-send-email.pl --verbose -k aws-credentials -r
From: evan@example.com
To: evan@example.com
Subject: Email
Chicken: yummy
Cats: yucky
X-Zombies: kill them!
Now we're out of the header, into the body. Grand!
Sender
InvalidParameterValue
Illegal header 'Chicken'.
5ffad294-bd33-11e0-b6e3-affca9ad1eb5
Illegal header 'Chicken'.
Illegal header error. Now with the modified version:
[Tue Aug 02 14:15:17 evan@EvanMBP 63 amazon-email]$ ./ses-send-email-x-headers.pl --verbose -k aws-credentials -r From: evan@example.com To: evan@example.com Subject: Email Chicken: yummy Cats: yucky X-Zombies: kill them! Now we're out of the header, into the body. Grand! 000001318bb51442-c2cfb780-0604-4363-925a-54a57015e567-000000 64e75a47-bd33-11e0-9d09-8f08f31615ad
No errors, and I received the email below (extraneous SMTP headers added by Barracuda/Exchange removed):
From: To: Subject: Email X-Chicken: yummy X-ASG-Orig-Subj: Email X-Cats: yucky X-Zombies: kill them! Date: Tue, 2 Aug 2011 18:15:25 +0000 Message-ID: Content-Type: text/plain MIME-Version: 1.0 Now we're out of the header, into the body. Grand!
Illegal headers have been X-ified. Hope this helps someone.
I use Postfix’s header_check with IGNORE action to remove some illegal header produced by Outlook email client.
This is really really helpful!
It worked like charm in with Postfix!
Thanks a million!
worked flawlessly. thank you for sharing.