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.
Related
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.
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.
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.
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.
Is it possible to embed a reference to an image in an HTML email sent via MFMailComposeViewController on iPhone OS 3.0?
(void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename
doesn't seem to provide any way of either setting or reading the Content-ID header for an attachment, but is there some way to make this work?
I have seen apps that do this, but they're probably using SKPSMTPMessage...
I believe you can use an HTML tag in the email's body to achieve what you're looking for. It's not common, but the img's src attribute can actually be set to base-64 encoded image data. For instance, you can say "<img src='data:image/gif;base64,R0lGODlhUAAPAKIA......'>" and embed the image data inline.
Here's an article with more information:
https://web.archive.org/web/20140819061025/http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html
I know for a fact that this works in Mobile Safari, but I've never used it in Mail. It seems like it would work - I'm sure they use WebKit to render the HTML email messages as well.
Good luck!