7

我正在尝试在从 iPad 发送的 HTML 电子邮件的正文中包含图像。这似乎是不可能的。我曾尝试使用 CID 方法,但似乎在 iOS 中无法获取/设置附件的 CID。

我也尝试将图像嵌入到src="data:image/png;base64, blahblahblah". 当您撰写邮件时,它似乎可以工作,但在收到邮件时什么也没有出现。

有任何想法吗?

更多详细信息:我们不是在寻找将 JPEG/PNG 附加在电子邮件底部的解决方案。这很容易做到[composer addAttachmentData:mimeType:fileName:]

我们正在寻找一种解决方案,将图像内嵌在 HTML 格式的电子邮件中。您可以在该 IMG 标签周围加上一个链接,这样当收件人单击 IMG 时,他/她将被链接到应用程序的 iTunes 页面。

4

3 回答 3

6

从github下载NSData+base64类别。

然后执行以下操作:

NSData *imageData = [NSData dataWithContentsOfFile:pathInDocumentDirectory(imagePath)];
NSString *base64String = [imageData base64EncodedString];
NSString *imageString = [NSString stringWithFormat:@"data:image/png;base64,%@", base64String];

最后,将 放在imageString您希望此图像出现的 HTML 正文中。

希望能帮助到你!

于 2012-12-06T10:23:52.613 回答
1

来自iphone 电子邮件附件

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
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];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];  
于 2012-12-05T18:45:12.317 回答
0

要在 gmail 中显示图像,您可以:

MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
    mailCont.mailComposeDelegate = self; 

    NSMutableString *emailBody = [[NSMutableString alloc] initWithCapacity:20];

    NSString *linkimg = @"https://idrivethru.com/iDriveThruWeb/faces/javax.faces.resource/idrivethru_logo.png?ln=images";

    //Add the image
    [emailBody appendFormat:@"<p><a href = 'https://idrivethru.com/'> <img src='%@' align='centre' alt='iDriveThru.com'> </a></p><br/>", linkimg];

    [emailBody appendString:@"<p>This is an email with an embeded image right <b>above</b> this text</p>"];

    //NSLog(@"%@",emailBody);

    [mailCont setMessageBody:emailBody isHTML:YES];
    [self presentViewController:mailCont animated:YES completion:nil];
于 2015-12-29T21:50:43.653 回答