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:
Delete that and paste this in its place:
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! <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/"> <Error> <Type>Sender</Type> <Code>InvalidParameterValue</Code> <Message>Illegal header 'Chicken'.</Message> </Error> <RequestId>5ffad294-bd33-11e0-b6e3-affca9ad1eb5</RequestId> </ErrorResponse> 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! <SendRawEmailResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/"> <SendRawEmailResult> <MessageId>000001318bb51442-c2cfb780-0604-4363-925a-54a57015e567-000000</MessageId> </SendRawEmailResult> <ResponseMetadata> <RequestId>64e75a47-bd33-11e0-9d09-8f08f31615ad</RequestId> </ResponseMetadata> </SendRawEmailResponse>
No errors, and I received the email below (extraneous SMTP headers added by Barracuda/Exchange removed):
From: <evan@example.com> To: <evan@example.com> 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: <000001318bb51442-c2cfb780-0604-4363-925a-54a57015e567-000000@email.amazonses.com> 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.