如何在电子邮件正文中发送图像?

时间:2013-02-13 17:33:35

标签: iphone ios6 base64 mfmailcomposeviewcontroller

我正在使用此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];

以上代码的屏幕显示

enter image description here

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

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

1 个答案:

答案 0 :(得分:-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];
    }