Display local image on iPhone

In my application, I am composing an HMTL email with 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 replaced the placeholders with data from the application. Thus, I compose the body of the letter I want to send. All this works very well, except for the fact that in my HTML file I have the <img src='imageplaceholderpath' /> . Somehow, I canโ€™t understand why I have to replace this imageplaceholderpath in order to refer to the image that is in my application. Is this a valid approach in general, and if so, what will be the syntax / logic of the path that I should put there? I appreciate your ideas! Regards Sjakelien

+3
source share
5 answers

Unfortunately, this is not supported by the iPhone 3.x API.

http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

This will require a Content-ID: to be part of the attachment, but it is not.

  - (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename 
+4
source

Please note that using URI data: will not work for all email clients. Those that use IE as a rendering mechanism do not support it at all if IE8 is not installed, and even then according to Wikipedia , data: URIs are limited to a maximum of 32 KB.

The easiest way to get this to work is to place the image on your own server somewhere and link to it using the full http: // URI. If you cannot do this for any reason (perhaps the image is being created as part of using your application), you can try adding the image as part of the MIME and link to it from HTML.

My email client does not download deleted images automatically, but some spam mails still have images when I open it. Here's how it works:

Attach the image to your mail as suggested by yonel. Somehow you also need to add the Content-ID: header to this part. The contents of this header are then used as the src attribute in your image. The spam message looks like this in HTML:

 <img src="cid: image001.jpg@01CACC43.7035CE50 "> 

The attachment subcategory looks like this:

 Content-Type: image/jpeg; name="image001.jpg" Content-Transfer-Encoding: base64 Content-ID: < image001.jpg@01CACC43.7035CE50 > 

Looking at the documentation on addAttachmentData:mimeType:fileName: I assume that you will not be able to get this to work, and you will have to think about sending emails using raw SMTP.

+3
source
+1
source

I do not think that you can embed images as part of an email message in a regular email client. However, it seems that you can include image data directly in HTML as base64 encoded data. This is a rather non-standard way of doing things, so email may not display completely on all email clients.

See this question for more details, and sample code for this forum post

0
source

I donโ€™t know if HTML format is needed for you, but the actual implementation of the image in the email can be achieved without using HTML, only with the image as an attachment.

Just see how this is achieved here:

http://iphone-dev-tips.alterplay.com/2009/11/attaching-image-of-uiview-to-email.html

the decisive role is this:

 //   NSData * myData = UIImagePNGR (); [controller addAttachmentData: myData mimeType: @ "image/png" fileName: @ "route" ]; 

You get a PNG representation of your UIImage (like NSDataโ€‹โ€‹CODE>) .

0
source

All Articles