且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

要在iOS中发送电子邮件,其中包含电子邮件正文中的图像和文字

更新时间:2022-12-03 10:15:45

您可以使用HTML内容与img标签进行此操作。您可以使用以下代码:

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];