MIME Emails - PDF and Content-ID - email

We are sending Emails using The MIME-Format.
(Underlying language is Java, using MultiPartEmail).
It has been reported by customers that their system reads the .pdf-Attachment of our emails twice.
The reason for this is, apparently, the lack of a Content-ID for the attachment.
I'm trying to fix this but found really vague information about the content-ID. Reading the standard i figured it is just supposed to be some unique ID in the form of <ID#domain>.
So i added this into our email generation, so that the "slot" which references the .pdf-attachment looks something like this:
------=_Part_0_12345667890
Content-Type: application/pdf;
name=theName.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=theName.pdf
Content-ID: <1431939868331#domain>
Is that all there is about it? The number is current time in milliseconds.
I'm unclear about the domain. Is it critical that this domain is exactly the right one?
And how can i understand this Content-ID attribute? Is it simply what i think it is: an ID so that attachments can be uniquly referenced by some email-systems or is there more to it? Why is the domain important?
Edit: I don't know if its related, but it seems the .pdf-Attachment doesnt show in the iPhone Mail software. I can't think of any other reason it would not show, as .pdf is surely supported and the files are also quite small. (The icon of an attachment shows in the overview-list but the attachment is nowhere referenced in the opened email)

To answer my own question:
Yes, it does the trick for many email services. There just has to be some kind of ID for the elements contained in MIME and then they are rendered and read correctly.

Related

How to select a URL from an email in mutt and open it in a web browser?

When I read mails I sometimes would like to select one of the links in the mail's text to open it in a web browser.
Before you answer, I know there is urlview, but there are also BASE64-encoded (or other transfer encodings) mails from which urlview does not find any URLs. Then there are also HTML-only mails that can also be encoded with transfer encodings.
I wonder if there is a trivial and/or nice solution that I couldn't find. I cannot be the only one with this problem. It does not need to be based on urlview, of course.
urlview will work if you employ the "pipe_decode" setting. Example use in a macro, binding to "\u":
macro index,pager \\u "<enter-command>set pipe_decode = yes<enter><pipe-message>urlview<enter><enter-command>set pipe_decode = no<enter>" "view URLs"
with urlscan there exists a worthy successor to urlview.
Support for emails in quoted-printable and base64 encodings. [..] For HTML mails, a crude parser is used to render the HTML into text.

Standarts for email source code

I am looking for standarts for email source code, just to know how to generate it using php.
My specific problem is with multipart/mixed email.
The email's subject is in cyrilic and when I am sending email it arives without errors, but subject of email can't be read. There is some problem with encoding.
Here is my email header:
From: no-reply#sample.eu\n
Reply-To: no-reply#sample.eu\n
Cc:\n
Bcc:\n
X-Priority: 1 (Highest)\n
X-Mailer: PHP/5.3.29\n
MIME-Version: 1.0\n
Content-Type: multipart/mixed;\n
boundary="==Multipart_Boundary_x3865d75cb66632b12851874c2aafd492x"\n
Please help!
The email standard is pretty large, but you should be able to work through the broad picture in a few days. The wikipedia page for email has links to all the RFC standards for the message format. It also has a broad overview of the format.
The standard for the main format is defined here. Mime/multimedia attachments are covered here and here.
IMHO, I would try to find a library to deal with this sort of stuff. It's easy to make mistakes when you are formatting this on your own. Here is one in PEAR that seems to do what you need.
Or, instead of trying to figure out how to do this in php, try to use a language with better unicode support like Python3 or Perl5 that actually does this for you automatically. You'll waste a lot less time.

Replying to other email

I'm building webmail with PhpMailer.
I need advice about replaying to other email.
How to attach previous email? Should I simply attach it as a file - I think it's not good.
I prefer attach email text, but how? Using only blockquote? But what about previous mail's styles? I see in thunderbird blockquote with cite="mid:hash" attribute. What is it?
Maybe PhpMailer has some options regarding this?
It's generally pretty straightforward. Read this about how to deal with the headers (use addCustomHeader to set them) so that mail clients can identify it as a reply.
There's no particular standard for what to do with the body, though it's common to copy all the lines of the original body into the new message, preceded by >, though you could wrap it in a blockquote in HTML, or some other formatting. It's up to you what you do with attachments.

Converting JPEG in text format from email message source back into JPEG

I received an email a while ago with an image attachment in it. Since then, it seems hotmail has stopped hosting the image for me as when I open the message, the image is no longer available.
However, the message source is still intact, and if I'm not wrong, the message source - in text form - also contains the image.
The problem is of course it is in text form. The part which (I believe) contains the image looks something like this: (Just the first few lines)
--Apple-Mail-2--733971985
Content-Disposition: inline; filename=photo.JPG Content-Id:
<3F8BDC26-81F3-4BA2-9071-53E78CB3DB63/photo.JPG>
Content-Type: image/jpeg; name=photo.JPG Content-Transfer-Encoding:
base64
/9j/4AAQSkZJRgABAQEASABIAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdC
IFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAA
AADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFj
cHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaAAACGAAA
ABRnWFlaAAACLAAAABRiWFlaAAACQAAAABRkbW5kAAACVAAAAHBkbWRkAAACxAAAAIh2dWVkAAAD
TAAAAIZ2aWV3AAAD1AAAACRsdW1pAAAD+AAAABRtZWFzAAAEDAAAACR0ZWNoAAAEMAAAAAxyVFJD
It was sent from my iPhone into Hotmail.
Is this text representing the image that I am missing? I don't believe there is a program out there that can convert this for me, so I am willing to write my own program to do it. Question is, is this even possible?
Yes, this is entirely possible, by various methods. If you have the entire message source, you could save it into a file (something like *.eml) and open it in a mail client (e.g. Mozilla Thunderbird); this should show you the entire message including the attached image.
If not, it's still possible: as you can see from the headers, the image is base64-encoded. You need to revert this transformation - either using your own code (e.g. PHP has base64_decode()), or through various base64-decoders available online (e.g. this). The part you want to decode is the block starting with /9j/4AAQSk in this case. Rename the resulting file photo.JPG (as indicated in the e-mail headers) and you're done.
Note that this requires you to verify that you have put the entire base64-encoded file through the decoder - base64 has no marker to detect the end of file.

Display local image in iPhone HTML mail

In my app, I am composing an HMTL email message with the 3.0+ MFMailComposeViewController.
To do this, I created an HTML file, with some placeholders.
In my code, I read the HTML file, and with replaceOccurrencesOfString, I replace the placeholders with data from the app.
In that way, I compose the body of the email I want to send out.
This is all working very nicely, except for the fact, that in my HTML file, I have an <img src='imageplaceholderpath' /> tag.
Somehow, I cannot figure out, with what I should replace this imageplaceholderpath, in order to refer to an image that resides in my app.
Is this a valid approach at all, and if so, what would be the syntax/logic behind the path I should put there?
I do appreciate your insights!
Regards
Sjakelien
Unfortunately this is not supported by the iPhone 3.x APIs.
http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
It would require Content-ID: to be part of the attachment subpart but it is not.
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename
Note that using data: URIs won't work across all mail clients. Those that use IE as a rendering engine don't support it at all unless IE8 is installed, and even then, according to Wikipedia, data: URIs are limited to 32 KB maximum.
The very simplest way to get this to work is to put the image on your own server somewhere, and reference it using a full http:// URI. If you can't do that for some reason (maybe the image is generated as part of using your app), then you can try attaching the image as a MIME sub-part and referencing it from the HTML.
My mail client doesn't load remote images automatically, but some spam still has images when I open it. This is how it works:
Attach an image to your mail as suggested by yonel. Somehow you need to also add a Content-ID: header to the sub-part. The contents of this header are then used as the src attribute on your image. My spam message looks like this in the HTML:
<img src="cid:image001.jpg#01CACC43.7035CE50">
The attachment sub-part looks like:
Content-Type: image/jpeg;
name="image001.jpg"
Content-Transfer-Encoding: base64
Content-ID: <image001.jpg#01CACC43.7035CE50>
Looking at the documentation for addAttachmentData:mimeType:fileName:, my guess is that you won't be able to get this to work and will have to consider sending the email using raw SMTP.
I found this post, that answers most of my questions: http://www.iphonedevsdk.com/forum/iphone-sdk-development/25021-embedding-image-email-body.html.
I don't think you can embed the images as part of the email in the way a normal email client would. However it seems that you can include the image data directly in the HTML as base64 encoded data. This is quite a non-standard way of doing things, so the email might not display perfectly on all email clients.
See this question for more, and the sample code on this forum post
I don't know if the HTML format is a must have for you, but actually embedding an image in an email can be achieved without using HTML, just with image as attachment.
Just have a look at the way it is achieved here :
http://iphone-dev-tips.alterplay.com/2009/11/attaching-image-of-uiview-to-email.html
the crucial part is this :
// ATTACHING A SCREENSHOT
NSData *myData = UIImagePNGRepresentation(screenshot);
[controller addAttachmentData:myData mimeType:#"image/png" fileName:#"route"];
You get the PNG representation of your UIImage (as NSData) and you attach it yo your email.