Whats wrong with my multipart/alternative Email? - email

I'm trying to build up my own Email sending class and it seems I have a bug with my MIME.
If someone could find the error or tell me about a working MIME Validator I would really appreciate that.
Thanks in advance
JD
To: me#mydomain.com
Subject: Test Alternate
X-PHP-Originating-Script: 1000:SendMail.class.php
MIME-Version: 1.0
From: me#mydomain.com
Content-Type: multipart/mixed;
boundary="MultipartMail53dfa8ade817e"
Message-Id: <20140804153717.EA93E160195#myDevice>
Date: Mon, 4 Aug 2014 17:37:17 +0200 (CEST)
X-RCPT-TO: <me#mydomain.com>
Status:
X-UIDL: 706801872
X-IMail-ThreadID: c9b40003d631c851
--MultipartMail53dfa8ade817e
Content-Type: multipart/alternative;
boundary="Alternative53dfa8ade8378"
--Alternative53dfa8ade8378
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Some Text content
--Alternative53dfa8ade8378
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Das ist Text
--
Text
*Some more Text*
Text
--Alternative53dfa8ade8378--
--MultipartMail53dfa8ade817e--

There's a few things "wrong" with your email:
Firstly, you have a non-header in your header:
To: me#mydomain.com
*Test Alternate*
X-PHP-Originating-Script: 1000:SendMail.class.php
(*'s around the broken bit)
Secondly, (and probably your main issue with Thunderbird) is that your multipart/alternative has the child parts in the wrong order. The way that multipart/alternative is supposed to work is that the last part is supposed to be the form that is closest to what the original author of the message intended for you to see (IOW what he/she saw in their WYSIWYG editor).
TL;DR
Put the text/html part last and the text/plain part first within the multipart/alternative.

Related

Multipart/mixed e-mail not displayed correctly in Outlook/Microsoft Mail, text displays as attachment

I'm trying to create e-mail with multipart/mixed content, with 2 HTML BodyParts (no attachments).
MIME-Version: 1.0
Date: Thu, 9 Dec 2021 13:44:01 +0100
Message-ID: <id#localhost>
Subject: This is Subject
From: test <foo#bar.com>
To: foo2#bar.com
Content-Type: multipart/mixed;
boundary="----main_boundary"
------main_boundary
Content-Type: multipart/alternative;
boundary="----header_boundary"
------header_boundary
Content-Type: text/html
Content-Transfer-Encoding: 7bit
<h2>Header before the main body</h2>
------header_boundary--
------main_boundary
Content-Type: multipart/alternative; boundary=boundary1
Content-Disposition: inline
--boundary1
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<b>Just HTML</b>
--boundary1--
------main_boundary--
This e-mail renders fine in all clients even mobile ones I've tested except Outlook and Windows Mail. Seems like Microsoft's clients ignore the Second body part and displays only the Header before the main body part.
Is there any workaround? I don't want to create just one html content.

Body of emails with ical-event is not shown

I am sending an HTML email with an ical invitation attached.
I'm facing the issue that many mail-clients do not show the body of the mail properly.
Thunderbird shows neither the plain-text nor html e-mail body, only the raw invitation
Outlook 2013 seems to show the html-body but totally messed up. Only the raw text contained within the html-mail is shown. CSS seems to be ignored
This issue occurs only if the ical-attachment is present. If I send the same mail without the ical attachment, everything works fine.
Is there maybe some kind of header that tells mail-clients to also show the mail-body in addition to the ical-invitation or what else could I be missing?
Date: Thu, 26 Aug 2021 08:47:10 +0200 (CEST)
From: John Doe <john#doe.com>
To: Max Mustermann <max#mustermann.de>
Subject: =?UTF-8?Q?Best=C3=A4tigung_Ihres_Termins_am_18.08.2020?=
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_6_1140395501.1629960429000"
------=_Part_6_1140395501.1629960429000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<... my plain text mail ...>
------=_Part_6_1140395501.1629960429000
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!doctype html>
<... my HTML email ...>
------=_Part_6_1140395501.1629960429000
Content-Type: text/calendar; charset=UTF-8; method=REQUEST
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
PRODID:-//My Company//My App//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20210826T064710Z
UID:38c15e72-12cf-44d1-97ea-a5a753f4b724
SUMMARY:Your Appointment
DESCRIPTION:Passwort: secure123\nhttps://example.com/meeting
LOCATION:Online-Meeting
DTSTART;TZID=Europe/Berlin:20200818T153000
ATTENDEE;PARTSTAT=ACCEPTED;RSVP=FALSE;CN=John Doe;EMAIL=john#doe.com:mailto:john#doe.com
ATTENDEE;PARTSTAT=ACCEPTED;RSVP=FALSE;CN=Max Mustermann;EMAIL=max#mustermann.de:mailto:max#mustermann.de
END:VEVENT
END:VCALENDAR
------=_Part_6_1140395501.1629960429000--
I had a similar problem when sending ical Attachements from Rails and trying to check the resulting mails with MailCatcher.
The problem is the Content-Transfer-Encoding: 7bit (typically used for binary files) but your attachment is more like plain text.
Try to use quoted-printable instead, like in this example:
----==_mimepart_612e500330e6c_dd52137407244b
Content-Type: text/calendar;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename=A-1105.ics
Content-ID: <612e500337894_dd521374072738#Nielss-MBP.localdomain.mail>
BEGIN:VCALENDAR=0D
CALSCALE:GREGORIAN=0D
PRODID:-//Foxtag//DE=0D
X-WR-TIMEZONE:Europe/Amsterdam=0D
VERSION:2.0=0D
METHOD:PUBLISH=0D
BEGIN:VEVENT=0D
...
In Rails you can set the encoding when adding attachments like this:
attachments['mycalendar.ics'] = {
mime_type: "text/calendar",
encoding: "quoted-printable",
content: #ical_content_as_string
}

How to compose multipart MIME mixed message to display it correctly in Outlook

I am using java code to compose and send e-mail messages to MS Outlook 365 accounts.
The message is composed as following:
plain text part;
html part containing only table;
plain text part;
File attachment.
I expect that outlook displays part 1-3 as message body and the last part as attachment. Instead it displays only first part as message itself and puts the rest parts as separate attachments.
I have played with different headers, but result is the same. Is it some feature of MS stack (exchange, outlook, etc.) or I did something wrong?
The raw message is here
Date: Mon, 5 Jun 2017 12:01:47 -0700 (PDT)
From: no-reply#example.com
To: consumer#example.com
Message-ID: <some id>
Subject: Test email
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_0_2350964.1496689307498"
------=_Part_0_2350964.1496689307498
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content before table
------=_Part_0_2350964.1496689307498
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
<html><body><table><tr><td>First parameter</td><td>value</td></tr><tr><td>Second row</td><td>42</td></tr></table></body></html>
------=_Part_0_2350964.1496689307498
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
This content should be placed after table
------=_Part_0_2350964.1496689307498
Content-Type: application/octet-stream;
name="report.xls"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="report.xls"
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAOwADAP7/CQAGAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA
<skipped>
------=_Part_0_2350964.1496689307498--
As a result I see only "Content before table" line, two attachments like "ATT01.html" and "ATT02.txt" and my original attachment "report.xls".
I have found one related topic at some forum saying that this problem should not appear since Outlook 2010 or so, but I can see it in the latest version both in desktop app and the web application.
The workaround solution to put everything in html part requires more work, because text parts are generated by other components.
You are grouping the parts incorrectly. It must be
1. Outer message, multipart/mixed
2. multipart/related
2.a text/plain
2.b text/html
3. attachment.

What is the correct content-type and document structure for an email that only contains an text/html part

First off- I'm fixing up an existing open source library. While I know that people SHOULD send a plaintext version of a message when they send an html email, this isn't a best-practices question. If I don't maintain backwards compatibility, they won't accept my patch.
I'm trying to figure out how to best handle situations where ONLY an html email is sent.
The library currently generates this:
MIME-Version: 1.0
Content-Type: text/html;
Hello, World
But every html-only message I've seen in my inbox shows:
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_1935495_1732146301.1367384830372"
----=_Part_1935495_1732146301.1367384830372
Content-Type: text/html;
Hello, World
----=_Part_1935495_1732146301.1367384830372--
I can't figure out if this is a best-practice or a requirement
I've been through :
https://www.rfc-editor.org/rfc/rfc2557
http://www.ietf.org/rfc/rfc2854.txt
but couldn't find any information.
Use Content-Type: Multipart/related; type=Text/HTML:
From: user1#example.com
To: user2#example.com
Subject: An example
Mime-Version: 1.0
Content-Base: http://www.example.com
Content-Type: Multipart/related; boundary="boundary-example-1";type=Text/HTML
--boundary-example-1
Content-Type: Text/HTML; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
... text of the HTML document, which might contain a hyperlink
to the other body part, for example through a statement such as:
<IMG SRC="/images/ie5.gif" ALT="Internet Explorer logo">
Example of a copyright sign encoded with Quoted-Printable: =A9
Example of a copyright sign mapped onto HTML markup: ยจ
References
MIME Hierarchies of Body Parts
MIME Standard Header Fields
Handling Binary Data in XML Documents
Direct Mailer Requirements
Multipart Messages
HTML Threading:
Conventions for use of HTML in email

MIME "multipart/related" Structure and Apple Mail. Is it a Bug?

I build a E-Mail with PHP Zend Framework Class Zend_Mail. There is one text- and one html-part with related inline-images. I want to attach one pdf-file too.
My question is about the mime-structure. Two options are possible:
option 1:
Content-Type: multipart/mixed
Content-Type: multipart/alternative
Content-Type: text/plain; charset=UTF-8
Content-Type: multipart/related
Content-Type: text/html; charset=UTF-8
Content-Type: image/jpeg
Content-Type: image/jpeg
Content-Type: image/png
Content-Type: application/pdf
option 2:
Content-Type: multipart/related;
Content-Type: multipart/alternative;
Content-Type: text/plain; charset=utf-8
Content-Type: text/html; charset=utf-8
Content-Type: image/jpeg
Content-Type: image/jpeg
Content-Type: image/png
Content-Type: application/pdf
option 2 is built by Zend_Mail, but the pdf is not recognized at Apple Mail Application. It's fine in Thunderbird 3 and Outlook 2007. Only in Apple Mail the PDF-Attachment isn't recognized.
option 1 is ok in Apple Mail, Thunderbord and Outlook. But it would be a little bit tricky to get this structure out of the Zend Framework Class Zend_Mail.
Is this a Bug in Apple Mail or is option 2 not normative?
kind regards,
sn
Have you tryied specifying the type ? see this page http://framework.zend.com/manual/en/zend.mail.attachments.html
i use this
$obj_MailAttachment = new Zend_Mime_Part($allegato);
$obj_MailAttachment->type = 'application/pdf';
$obj_MailAttachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$obj_MailAttachment->encoding = Zend_Mime::ENCODING_BASE64;
$obj_MailAttachment->filename = 'ordine'.$ordine['numero'].'.pdf';
...
$mail->addAttachment($obj_MailAttachment);
Both options are violations of RFC822, the header-lines MUST start on the first character of their line; this is important because hearer-folding is triggered by that first character being whitespace SP (#32) or HT (#09), IIRC.
Example:
Content-Type: text/html; charset=UTF-8
and
Content-Type: text/html;
charset=UTF-8
are exactly equivalent.
The proper way to do what you're (apparently) attempting is by using the boundary attribute is something like this:
Content-Type: multipart/mixed; boundary="1610edf3f7626f0847a5e75c55287644"
OTHER-HEADERS
--1610edf3f7626f0847a5e75c55287644
Content-Type: multipart/mixed; boundary="embedded_boundary"
OTHER-HEADERS
--embedded_boundary
NESTED-MESSAGE-GOES-HERE
--embedded_boundary--
--1610edf3f7626f0847a5e75c55287644--
One of the parts of nested-portion would contain the PDF-attachment.
Ref:
http://www.faqs.org/rfcs/rfc2822.html and the links provided here: Are email headers case sensitive?