我有这段代码,它应该将 HTML 文件附加到电子邮件中,并在电子邮件正文中显示 HTML 文件的内容。HTML 文件中引用了一个图像 (reading.png),每隔一行显示。但是,它不会显示在电子邮件正文中。我该怎么做才能让它显示?
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self; // set delegate to notify us what's happen'in
[mailer setSubject:[NSString stringWithFormat: @"Site Readings for: %@", gSiteID.globalSiteID]];
// add the image for the HTML
UIImage *toolImage = [UIImage imageNamed:@"reading.png"];
NSData *imageData = UIImagePNGRepresentation(toolImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"reading.png"];
// attach file
NSString *file = [[NSBundle mainBundle] pathForResource:@"Surveyor" ofType:@"txt"];
NSData *surveyorTxt= [NSData dataWithContentsOfFile: file];
[mailer addAttachmentData: surveyorTxt mimeType:@"text/html" fileName: @"Surveyor.txt"];
// display the file in the body of the email
NSString *reportBody;
reportBody = [[NSString alloc] initWithData:databuffer encoding:NSASCIIStringEncoding];
[mailer setMessageBody: reportBody isHTML:true]; // indicate the body is html
[self presentModalViewController: mailer animated:TRUE];
这是要显示的 HTML:
<html>
<head>
<link rel='stylesheet' type='text/css' href='default.css'/>
</head>
<body>
STA: TBM "J" Elev: 19.76<br>Desc: USGS Test Site
<div>
<table border class="boldtable">
<tr BGCOLOR="ADDAFE">
<th>STA </th>
<th>BS </th>
<th>HI </th>
<th>FS </th>
<th>ELEV </th>
<th>Desc</th>
</tr>
<p><tr>
<td> TBM "J"</td>
<td></td><td></td><td></td>
<td>19.76</td>
<td>USGS Test Site</td>
<p><tr
><td><img src="reading.png" align=center></td><td>3.14</td><td valign="middle">22.90</td>
更新:我认为我不够清楚......在传出消息中显示的 HTML 中,应该有一个图像出现在整个 HTML 中。我将图像附加到消息中没有问题,但它没有出现在我想要的 HTML 中。很明显,将图像附加到消息中是行不通的……(我认为可以)。
HTH...