knw500
knw500

Reputation: 512

iPhone SDK Add Image to the Body of an Email?

I was wondering if anyone knew how to use an image in the body of an email when the mail app is opened. Can anyone help?

Thanks in advance Kieran.

Upvotes: 1

Views: 3440

Answers (2)

dusker
dusker

Reputation: 580

NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1);
MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
[viewController addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];

I wrote the code by hand so it might have some mistake, but you should get the general idea.

Upvotes: 10

teanet
teanet

Reputation: 129

you can attach image in mail body using base64 encoding

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];

NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
NSString *imageStr = [imageData base64EncodingWithLineLength:[imageData length]];

NSString *htmlStr = [NSString stringWithFormat:@".....<img src='data:image/jpeg;base64,%@'>.......",imageStr];

[mailComposer setMessageBody:htmlStr isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
        [mailComposer release];

Upvotes: 7

Related Questions