在iOS中,希望使用邮件编辑器在电子邮件正文(非附件)中发送包含嵌入图像和文本的电子邮件。有人可以帮忙吗?
答案 0 :(得分:3)
您可以使用带有img标记的HTML内容来执行此操作。您可以使用以下代码:
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];
答案 1 :(得分: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];
}