Parsing email with Python

You must ensure that the lines are not accidentally broken (as they are above, though it’s hard to say if that was a copy-paste problem) — with an intact message such as: Received: (qmail 8580 invoked from network); 15 Jun 2010 21:43:22 -0400 Received: from mail-fx0-f44.google.com (209.85.161.44) by ip-73-187-35-131.ip.secureserver.net with SMTP; 15 Jun 2010 21:43:22 … Read more

How can I get an email message’s text content using Python?

In a multipart e-mail, email.message.Message.get_payload() returns a list with one item for each part. The easiest way is to walk the message and get the payload on each part: import email msg = email.message_from_string(raw_message) for part in msg.walk(): # each part is a either non-multipart, or another multipart message # that contains further parts… Message … Read more

Correct Apache AddType directives for font MIME types

I realize that this question is old, but for anyone looking for a quick copy/paste for adding font MIME types to their .htaccess: <IfModule mod_mime.c> AddType application/vnd.ms-fontobject .eot AddType application/x-font-opentype .otf AddType image/svg+xml .svg AddType application/x-font-ttf .ttf AddType application/font-woff .woff AddType application/font-woff2 .woff2 </IfModule>

How to create an email with embedded images that is compatible with the most mail clients

I’ve had success with exactly the same headers as you’re using, with the following differences: Embedded is not a valid value for the Content-Disposition header. attachment should be fine. inline should also be fine, though I’ve usually seen attachment for multipart/related embedded images. The value of the Content-ID header is supposed to be in the … Read more

How to read text inside body of mail using javax.mail

This answer extends yurin’s answer. The issue he brought up was that the content of a MimeMultipart may itself be another MimeMultipart. The getTextFromMimeMultipart() method below recurses in such cases on the content until the message body has been fully parsed. private String getTextFromMessage(Message message) throws MessagingException, IOException { String result = “”; if (message.isMimeType(“text/plain”)) … Read more

Email from PHP has broken Subject header encoding

Update   For a more practical and up-to-date answer, have a look at Palec’s answer. The specified character encoding in Content-Type does only describe the character encoding of the message body but not the header. You need to use the encoded-word syntax with either the quoted-printable encoding or the Base64 encoding: encoded-word = “=?” charset “?” encoding … Read more

How to use the CSV MIME-type?

You could try to force the browser to open a “Save As…” dialog by doing something like: header(‘Content-type: text/csv’); header(‘Content-disposition: attachment;filename=MyVerySpecial.csv’); echo “cell 1, cell 2”; Which should work across most major browsers.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)