如何在电子邮件正文上显示图像 - 使用sksmtplibrary

时间:2013-03-28 04:44:50

标签: ios email smtp

我有一个html内容作为我的电子邮件正文。我需要在我的html身上显示一个图像。我已尝试将图像附加到电子邮件并使用html图像标记中的文件名。但图像没有显示。我也尝试使用dataUri,它在某些电子邮件客户端中不起作用。

这是我的代码。

NSData * imageData = [[NSDataalloc] initWithContentsOfURL: [NSURLURLWithString: @"http://wf.vanillicon.com/f6f63a5a0d149275772ff1cf22595988_100.png"]];
NSString *strFileName = [NSStringWithFormat:@"MyPicture.png"];

NSString *strFormat = [NSStringWithFormat:@"image/png;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName];
NSString *strFormat2 = [NSStringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName];
NSDictionary *vcfPart = [NSDictionarydictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
                         strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArrayarrayWithObject:vcfPart];

NSDictionary *plainPart = [NSDictionarydictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                           @"<img src=\"MyPicture.png\" width=\"100px\" height=\"100px\" /><h1>Tui</h1>",kSKPSMTPPartMessageKey,
                          @"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArrayarrayWithObjects:plainPart,vcfPart,nil];

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

有时,当您发送HTML电子邮件,并且该HTML中的标记中有图像时,接收方的电子邮件客户端将不会自动显示图像。您可能需要点击电子邮件中的“显示图像”。