Sign in to follow this  

[web] What's wrong with this email?

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Edit 2: I've added a Content-Type: multipart/alternative block as the first part of the multipart/mixed message, and included within it the main message as two different parts - a dummy plaintext ("This is an HTML email") and an HTML one (with just the HTML one, some clients were displaying it as if it were text/plain). Outlook Express still has the message-not-on-server problem, but if I send myself a message from it even that has the problem, so I assume it's a server issue. Finally, Outlook, Live Mail and Ihola Mail (webmail) work... I still have no idea why the below doesn't work. Edit: I should say, I'm really not a fan of posting code - of any sort - and asking people to find out what's wrong with it. However, I'm at a complete loss here. [sad] I can't find any decent information on constructing multipart emails, just lots of sample code - none of which actually work. This is the closest I've got to a working solution. If I save the output data as a .eml file it can be opened fine in Outlook Express and Live Mail Desktop. However, if I try and view the email inside my inbox in Live Mail Desktop, it gives me the "Message is no longer available on the server" error (ie, the message is corrupted). I can see it and view its source using a webmail client.
X-POP3-From:	example@example.com
Return-path: <example@example.com>
Envelope-to: example@example.com
Delivery-date: Thu, 10 May 2007 12:29:31 +0100
Received: from example.com ([127.0.0.1])
	by example.com with esmtps (TLSv1:DES-CBC3-SHA:168)
	(Exim 4.54)
	id 1Hm6pv-0002in-Rq
	for example@example.com; Thu, 10 May 2007 12:29:31 +0100
Received: from example by example.com with local (Exim 4.54)
	id 1Hm6pv-0002aV-IO; Thu, 10 May 2007 12:29:31 +0100
To: example@example.com
Subject: I hate email
MIME-Version: 1.0
To: example@example.com
From: noreply@example.com
Content-Type: multipart/mixed;
    boundary="PHP-fd818dd7d82142c4c23f2441c4d025b0"
Message-Id: <E1Hm6pv-0002aV-IO@example.com>
Date: Thu, 10 May 2007 12:29:31 +0100

This is a multi-part message in MIME format.

--PHP-fd818dd7d82142c4c23f2441c4d025b0
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: base64

PHN0..[base64 content]..aXY+

--PHP-fd818dd7d82142c4c23f2441c4d025b0
Content-Type: application/pdf; name="Attached.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Attached.pdf"

JVBE..[base64 content]..GCg==

--PHP-fd818dd7d82142c4c23f2441c4d025b0--





The base64-encoded content is wrapped correctly, so no worries there. If I only have a single part in the message (same headers, boundary and so on; just remove the final attachment) it works fine. [Edited by - benryves on May 10, 2007 9:20:54 AM]

Share this post


Link to post
Share on other sites
I've suffered through this in the past, unfortunatly I can't share any relevant code :-(

I assume you have read RFC 2046?

I suggest you try and get this working with two text sections then add base64 stuff once that works. I would also suggest having at least one section with no Content-type (which defaults to US-Ascii), or explicitly specify a text/plain section (for testing/debugging to rule out rubbish reader implementations that assume they are going to find one).

The line break in "Content-Type: multipart/mixed;
boundary="PHP-fd818dd7d82142c4c23f2441c4d025b0"" is just a typo when you posted, right? Because that will break a lot of readers (which process line-by-line).

The only practical advice I can offer you is grab a copy of python+its mail libraries. Form a multi-part email and print it out. You may spot something you are doing wrong. I only suggest python as thats my prefered tool for this sort of thing, you can do the whole task interactivly in the interpreter and fix things/dig deeper as you go.

Good luck :-)

Alan

Share this post


Link to post
Share on other sites
Ah, you posted that as I made my edit. [smile]

Quote:
Original post by Alan Kemp
I suggest you try and get this working with two text sections then add base64 stuff once that works. I would also suggest having at least one section with no Content-type (which defaults to US-Ascii), or explicitly specify a text/plain section (for testing/debugging to rule out rubbish reader implementations that assume they are going to find one).
Indeed, I found out that missing out the text/plain session broke readers that were displaying the HTML as plaintext.

Quote:
The line break in "Content-Type: multipart/mixed;
boundary="PHP-fd818dd7d82142c4c23f2441c4d025b0"" is just a typo when you posted, right?
No, it was intentional. Outlook sticks them on different lines, to keep within the 78-column limit I assume, so I copied its example. Interesting, though, that some clients will choke on it...

Quote:
The only practical advice I can offer you is grab a copy of python+its mail libraries. Form a multi-part email and print it out.
Aye, this is what I've been doing with Outlook - probably not the best idea, but it seems to have worked thus far. [grin]

Thanks for your advice. I'll check the new functionality with a few clients, see what they make of it...

Share this post


Link to post
Share on other sites
A couple of things:

1) Do yourself a favour and get Thunderbird. Send yourself a message and hit Ctrl+U for the full source of the message. Much easier than outlook (at least the last Outlook I tested with).

2) The code you posted seems to be a multipart/mixed between base64 encoded HTML and PDF. I've never seen text/html encoded as base64. I don't even know if it's possible or if mail readers know what to do with it.

3) Can you post the source of the alternative-in-mixed that your edit2 is about?

4) If you nest mime blocks (alternative in mixed) then make sure you use different boundaries for each.

5) This is an e-mail generated by my PHP mailer (some parts snipped). It's slightly different from yours, because the attachments are inline (in this case, images referenced from the HTML source).


From - Thu May 10 22:47:34 2007
To: sander@example.com
From: sander@example.com
Return-Path: sander@example.com
MIME-Version: 1.0
Date: Thu, 10 May 2007 22:44:25 +0200
Message-Id: <fcd3e3561df72d1abb7d031b611d1ecc@example.com>
Content-Type: multipart/related; boundary="MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b"

--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b
Content-Type: multipart/alternative; boundary="MESSAGE_BOUNADRY_f09d3ebb08b33f709372699e9230d528"
This is a multi-part message in MIME format.

--MESSAGE_BOUNADRY_f09d3ebb08b33f709372699e9230d528
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit

This is the text part

--MESSAGE_BOUNADRY_f09d3ebb08b33f709372699e9230d528
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 8bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<body>

<p>This is the HTML part</p>

</body>
</html>

--MESSAGE_BOUNADRY_f09d3ebb08b33f709372699e9230d528--



--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b
Content-Type: image/gif;
name="image1.gif"
Content-Transfer-Encoding: base64
Content-ID: <pallets.gif>
Content-Disposition: attachment;
filename="image1.gif"

R0lGODdhgALIAOcAAAQCBDyGBHwCBKSOVHxGBLzClJwmBCxSBPTi5OSChNRGRESCBKwCBOyipMwi
<snip>
Mkopp6SySiuvxDJLLbfksksvvwQzTDHHJLNMM89EM00112SzTTfBDAgAOw==
--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b
Content-Type: image/gif;
name="image2.gif"
Content-Transfer-Encoding: base64
Content-ID: <vtc.gif>
Content-Disposition: attachment;
filename="image2.gif"

R0lGODdhgALIAOcAAAQCBKSClITCvMQCBMSCxLRCTJSirJRidNzCzIyCzLwiJKyitNRCRIS2xNxi
<snip>
1F/91n/92J/92r/93D/3AQEAOw==
--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b
Content-Type: image/gif;
name="image3.gif"
Content-Transfer-Encoding: base64
Content-ID: <trekker.gif>
Content-Disposition: attachment;
filename="image3.gif"

R0lGODdhgALIAOcAAAQCBCyGLHwCBLSCZIROHJzKhKwjDDyzPHx88rRCLNTGtLwmHBRCFLykgGyC
<snip>
AAA7
--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b
Content-Type: image/gif;
name="image4.gif"
Content-Transfer-Encoding: base64
Content-ID: <pendel.gif>
Content-Disposition: attachment;
filename="image4.gif"

R0lGODdhgALIAOcAAAQCBFyKXHzCfMTC/IxGRPyChCxCLMTixOTi/IyK/ExOnBwuHLSy/OTy5KTS
<snip>
V2W1VVdfhTVWWWeltVZbb8U1V1135bVXX38FNlhhhyUW2IAAADs=
--MIME_BOUNADRY_7510c02c4d824d98de73614342150b4b--






My e-mailer is written in PHP. You can have it under a GPL license if you want (based loosely off phpBB so I cannot give it under another license). Let me know if you want it.

Share this post


Link to post
Share on other sites
Quote:
2) The code you posted seems to be a multipart/mixed between base64 encoded HTML and PDF. I've never seen text/html encoded as base64. I don't even know if it's possible or if mail readers know what to do with it.
It's certainly supported by at least Outlook XP, Live Mail Desktop, Outlook Express 6, Thunderbird and Ihola Mail.

I've tried to avoid quoted-printable as it's harder than base64 encoding, especially since as far as I can see PHP does not provide any mechanism to quoted_printable_encode.

Quote:
3) Can you post the source of the alternative-in-mixed that your edit2 is about?


Sure:
X-POP3-From:	example@example.com
Return-path: <example@example.com>
Envelope-to: example@example.com
Delivery-date: Fri, 11 May 2007 13:25:51 +0100
Received: from example.com ([127.0.0.1])
by example.com with esmtps (TLSv1:DES-CBC3-SHA:168)
(Exim 4.54)
id 1HmUBz-0003bQ-24
for example@example.com; Fri, 11 May 2007 13:25:51 +0100
Received: from example by example.com with local (Exim 4.54)
id 1HmUBx-00080C-5P; Fri, 11 May 2007 13:25:49 +0100
To: example@example.com
Subject: Email works
MIME-Version: 1.0
To: example@example.com
From: example@example.com
Content-Type: multipart/mixed;
boundary="mix-4c2b560ea834ba181c7ee788bc0e48b1"
Message-Id: <E1HmUBx-00080C-5P@example.com>
Date: Fri, 11 May 2007 13:25:49 +0100

This is a multi-part message in MIME format.

--mix-4c2b560ea834ba181c7ee788bc0e48b1
Content-Type: multipart/alternative;
boundary="alt-4c2b560ea834ba181c7ee788bc0e48b1"


--alt-4c2b560ea834ba181c7ee788bc0e48b1
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is an HTML email.
--alt-4c2b560ea834ba181c7ee788bc0e48b1
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: base64

PH..*snip*..XY+

--alt-4c2b560ea834ba181c7ee788bc0e48b1--

--mix-4c2b560ea834ba181c7ee788bc0e48b1
Content-Type: application/pdf; name="Attached.pdf"
Content-disposition: attachment; filename="Attached.pdf"
Content-Transfer-Encoding: base64

JV..*snip*..Cg==

--mix-4c2b560ea834ba181c7ee788bc0e48b1--


Quote:
4) If you nest mime blocks (alternative in mixed) then make sure you use different boundaries for each.
Yep, I'd gathered that much. [smile]

Quote:
My e-mailer is written in PHP. You can have it under a GPL license if you want (based loosely off phpBB so I cannot give it under another license). Let me know if you want it.
Thank you for the offer, but given that the mailer now works - or, at least, appears to - I hopefully won't need to take advantage of it.

Share this post


Link to post
Share on other sites

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this