Base 64 encoded image in email - email

I'm trying to send an email programatically that has the images embedded, to eliminate dependency on access to our network, or hosting files externally (corporate security red tape etc. etc.)
I was able to do this by encoding the image to base 64. However, I'm having issues with specific clients. Most importantly, in Outlook, the image shows as a broken link. The same thing is happening in Windows (10) mail. The images render in several other clients (Blue Mail for Android, a non-stock iPhone client and the web based client for my ISP).
On a side it looks like Outlook is replacing "+" signs in the base64 to + , although I'm not sure if that's related or not. I can save the source of the outlook email (even with the + ) as an html file and view it in a browser fine.
I have tried encoding using different characters here : https://cryptii.com/pipes/hex-to-base64
...to avoid having "+" signs. None of the other variants worked, and in fact, they all broke the images in the other clients.
Any ideas?

Outlook (or rather Word, which renders HTML messages in Outlook), does not support embedded base64 encoded images. You would need to add image attachments, set their Content-id MIME header, and refer to images like that through the cid attribute (<img src="cid:xyz">)

Related

Unicode Symbols in Html Emails - Does Outlook mess them all up?

I would like to include some simple symbols in an HTML email - one being an unchecked checkbox, and the other being a checked checkbox.
Why not images?
This is for an Intranet email, so the user may view the email either when they are on the local network with the server, or outside. So I don't want to put images there. The client predominantly uses Outlook.
I thought I could just use unicode characters U+2610 Ballot Box and U+2611 Ballot Box with Check.
I know every vendor will customize their fonts, but when these two symbols are viewed in Outlook, they're totally screwed up.
Is there any simple and reliable way of having checkboxes in emails? Do I need to embed the images on every email?

Image in Email Subject using PHP

I want to add image like company logo in email subject using php mail function i have added
$subject = "<img src=\"https://www.donndraper.com/images/logo.png\" width=\"50px\">");
$header = "From: $email\n Content-Type: text/HTML;";
What JerrySeeger was trying to say, in a fairly condescending manner, is that e-mail does not support images in the subject.
The SMTP protocol was designed 20 years before HTML was even invented.
What you desire is simply not possible.
You cannot include custom images (such as your company logo), however, there are a limited number of Unicode images that you can use in the header.
Some clients render them by using color images rather than treat them as characters in a font. The following article has a few images comparing how various mobile devices render them:
Symbols in Subject Lines: How to Get Your Email Noticed
And you can see Wikipedia for a long list of the available characters, and if for some reason your font does not support those characters, the second link are bitmap renders of those characters:
Wikipedia: Miscellaneous Symbols
Online Uniode Character Map
#GUS well said.. and you guys are all wrong.
You may use any unicode utf-8 or Base64 in mail subject and latest Trend in mass Mailers.
its pretty easy to implement .

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.

How to serve .RTFs

I support a web-application that displays reports from a database. Occassionally, a report will contain an attachment (which is typically an image/document which is stored in the database as well).
We serve the attachment via a dynamic .htm resource which streams the attachment from the database, and populates the content-type based on what type of attachment it is (we support PDFs, RTFs, and various image formats)
For RTFs we've come across a problem. It seems a lot of Windows users don't defaultly have an assocation for the 'application/rtf' content-type (they do have an association for the *.rtf file extention). As a result, clicking on the link to the attachment doesn't do anything in Internet Explorer 6.
Returning 'application/msword' as the content-type seems to make the RTF viewable when clicking on the link, but only for people who have MS Office installed (some of the users won't have this installed, and will use alternate RTF readers, like OpenOffice).
This application is accessed publicly, so we don't have control of the user's machine settings.
Has anybody here solved this before? And how? Thanks!
Use application/octet-stream content-type to force download. Once it's downloaded, it should be viewable in whatever is registered to handle .rtf files.
In addition to the Content-Type header, you also need to add the following:
Content-Disposition: attachment; filename=my-document.rtf
Wordpad (which is on pretty much every Windows machine) can view RTF files. Is there an 'application/wordpad' content-type?
Alternatively, given the rarety of RTF files, your best solution might be to use a server-side component to open the RTF file, convert it to some other format (like PDF or straight HTML), and serve that to the requesting client. I don't know what language/platform you're using on the server side, so I don't know what to tell you to use for this.