问题
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.
回答1:
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];
回答2:
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.
来源:https://stackoverflow.com/questions/3049259/iphone-sdk-add-image-to-the-body-of-an-email