iPhone SDK Add Image to the Body of an Email?

南楼画角 提交于 2019-12-08 06:45:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!