Want to send a email with images and text in the body of email in iOS [closed]

眉间皱痕 提交于 2019-12-01 13:36:13

问题


In iOS, want to send a email with embedded images and text in the body of the email ( not attachment) using mail composer. Can anybody help ?


回答1:


You can use the HTML content with img tag for doing this. You can use the following code:

NSMutableString *imgContent = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
UIImage *imageData = [UIImage imageNamed:@"Midhun.png"];
NSData *imageDataInBase64 = [NSData dataWithData:UIImagePNGRepresentation(imageData)];
NSString *base64String = [imageDataInBase64 base64EncodedString];
[imgContent appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
[imgContent appendString:@"</body></html>"];

 MFMailComposeViewController *emailWin = [[MFMailComposeViewController alloc] init];
[emailWin setMessageBody:imgContent isHTML:YES];



回答2:


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

[mailComposer setMailComposeDelegate:self];

if ([MFMailComposeViewController canSendMail]) {

    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"kmlshyadav6@gmail.com", nil]];
    [mailComposer setSubject:@"Awesome Image(ur message or subject)"];
    [mailComposer setMessageBody:@"Hey,\n\nCheck out this awesome image!\n\n" isHTML:NO];
    [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];


        UIImage *lion = imageView.image;
        NSData *lionData = UIImageJPEGRepresentation(lion, 1);
        [mailComposer addAttachmentData:lionData mimeType:@"image/jpeg" fileName:@"01-Mac-OS-X-Lion.jpg"];



 }
    [self presentModalViewController:mailComposer animated:YES]; [mailComposer release];
} else {
    [mailComposer release];
}


来源:https://stackoverflow.com/questions/15766300/want-to-send-a-email-with-images-and-text-in-the-body-of-email-in-ios

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