tags:

views:

990

answers:

1

Hello all, I am using inbuilt composer of iPhone to send an email in my application. I want to add images to body of my email. Please remember I want to place images in the body and not want to attach the images to the email. I know how to attach them.

Its like I want to place multiple images in the body with some details for them in front of the respective image.

Is there any way to do that.

Like using html, the following code show me a question mark instead of an image.

NSData *imageData = [dbPersistenceObj getImageForEmail:[[imageIdArray objectAtIndex:i] intValue]]; 
NSString *encodedImage = [imageData description]; 
emailBody = [emailBody stringByAppendingFormat:@"<img src=\"cid:Img-1\"/>", imageData]; 
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"Img-1"];
+1  A: 

Edited after some experimentation

My original answer is not in fact a solution to the question. It appears that with MFMailComposeViewController you cannot reference attached images in an HTML email body using the cid: syntax.

If you attach the image after setting an HTML body the iPhone will internally use cid: to display the image, but only in the fashion in which it is normally represented in the composer view - so it's not that flexible.

Finally, it is possible to use the data:image/png;base64, embedded image source URL scheme but this does not seem to be widely supported by email clients - notably it does not fail gracefully in GMail.

Original answer:

Note: I haven't tried this.

Assuming that you are using MFMailComposeViewController in iPhone SDK 3.0+: You could try creating an HTML format email body and reference the attached image from within that HTML document.

HTML

...
<img src="cid:content-id"/> <!-- 'cid:' is important -->
...

Objective-C

...
[mailController addAttachmentData:pngData
                         mimeType:@"image/png"
                         fileName:@"content-id"];
[mailController setMessageBody:html isHTML:YES];
...
teabot
Can you help me more, I am using following code but see a '?' mark instead of image.NSData *imageData = [dbPersistenceObj getImageForEmail:[[imageIdArray objectAtIndex:i] intValue]]; NSString *encodedImage = [imageData description]; emailBody = [emailBody stringByAppendingFormat:@"<img src=\"cid:Img-1\"/>", imageData]; [picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"Img-1"];
rkb
Yeah I tried that one But that stuff dont work with the inbuilt MailComposer available in sdk3.0. Like it does display the images but while cliking the send button code breaks leaving message in debugger as image not found error.
rkb