0

嗨,我正在使用 MFMailComposer 在我的应用程序中发送邮件,我在其中附加了图像,并且在正文中存在 html 内容,最后我添加了谢谢,问候消息到邮件,但所有的文本内容,包括谢谢,问候即将到来作为一组,然后是我的图像附件,然后从我的 iPhone 发送的签名文本即将到来。我想感谢,关于从我的 iPhone 签名文本发送之前的文本,我怎样才能做到这一点?

4

1 回答 1

3

我已经使用Matt Gallagher的 NSData+Base64 将图像转换为 base64,所以在你的项目中添加:

首先像这样创建emailBody:

NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"] ;

[emailBody appendString:@"<p>Check Attachment</p>"];
UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
 //Convert the image into data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
 //Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
 //Add the encoded string to the emailBody string
 //Don't forget the "<b>" tags are required, the "<p>" tags are optional
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
 //You could repeat here with more text or images, otherwise
[emailBody appendString:[NSString stringWithFormat:@"<p><b>%@</b></p>",yourString]];// yourString after image here
 //close the HTML formatting
[emailBody appendString:@"</body></html>"];

像这样使用

   [MFMailDialog setMessageBody:emailBody isHTML:YES];

归功于这个答案。

于 2012-09-27T13:19:49.210 回答