我正在尝试将图像包含在从iPad发送的HTML电子邮件正文中。这似乎不可能。我曾尝试使用CID方法,但似乎在iOS中无法获取/设置附件的CID。
我还尝试使用src="data:image/png;base64, blahblahblah"
嵌入图片。撰写邮件时,它似乎有效,但收到邮件时没有任何内容。
有什么想法吗?
更多详情:
我们不是在寻找在电子邮件底部附加JPEG / PNG的解决方案。使用[composer addAttachmentData:mimeType:fileName:]
很容易做到。
我们正在寻找一种解决方案,其中图像嵌入在HTML格式的电子邮件中内嵌。您可以在该IMG标记周围包含一个链接,这样当收件人点击IMG时,他/她将被链接到该应用的iTunes页面。
答案 0 :(得分: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主体中您想要显示此图像的位置。
希望它有所帮助!
答案 1 :(得分:1)
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];
答案 2 :(得分: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];