【问题标题】:How to Send image in Email body?如何在电子邮件正文中发送图像?
【发布时间】:2013-02-13 17:33:35
【问题描述】:

我正在使用 link 在电子邮件正文中发送带有一些文本的图像,我的代码如下所示

NSString *urlString = @"url";
NSString *searchingurl = [NSString stringWithFormat:@"%@%@", urlString,idnumber];
NSString *string = [NSString stringWithFormat:@"%@<br><br>Item No :%@<br>Type :%@<br>Size : %@",searchingurl,str123,mytype,itemsize];
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
NSData *imageData = UIImageJPEGRepresentation(myImage, 1.0f);
NSString *encodedString = [imageData base64Encoding];
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",encodedString]];
[emailBody appendString:string];
[emailBody appendString:@"</body></html>"];
NSLog(@"%@",emailBody);
 MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:@""];
[emailDialog setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];

以上代码的截图

向雅虎发送邮件后,它会在 Mackbook 和 iphone 设备上显示我的图像和文本,当我将邮件发送到 Gmail 并在 iphone 设备中检查时,它会显示带文本的图像,但是当我在 Mackbook 中检查 gmail 时,它不会显示我的图片

有人可以指导我为什么我的图片没有显示在 PC 上的 Gmail 中。任何帮助都会得到帮助。谢谢

【问题讨论】:

  • @danh 但我有不同的情况,您的链接在图像之前显示文本,但我希望在电子邮件中的文本之前显示图像。
  • 你不能只是交换你添加的内容的顺序并添加具有 mime 类型 application/text 的文本
  • @danh 请发布答案,因为我仍然有一些疑问,如果我更改顺序然后我在电子邮件正文中添加我的图像的格式以及我需要添加它的位置,您的意思是 [emailDialog setMessageBody:emailBody isHTML :是];
  • @danh 我正在关注stackoverflow.com/questions/1527351/… 链接,但发送电子邮件后它不显示图像。

标签: iphone ios6 base64 mfmailcomposeviewcontroller


【解决方案1】:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Your subject"];


    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@""];
    //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
    //NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];

    [picker setToRecipients:toRecipients];
    //[picker setCcRecipients:ccRecipients];
    //[picker setBccRecipients:bccRecipients];


    NSLog(@"Video size >> %d",(videodta.length/1024)/1024);
  [picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"testapp"];

    // Fill out the email body text
    NSString *emailBody = @"Type your message here";
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    }

【讨论】:

  • 是的,我知道这种方法,但我在图片下方显示了一些文字,所以这就是为什么这种方法不适合我。
  • 你不能添加多个文本..只有名字
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 2017-01-16
  • 2013-01-14
  • 2015-11-27
  • 2018-05-05
  • 2012-09-20
  • 1970-01-01
相关资源
最近更新 更多