I have this code, which is supposed to attach a HTML file to the email, and also display the contents of the HTML file in the body of the email. There is an image (reading.png) referenced in the HTML file that get’s displayed every-other line. However, it is NOT being displayed in the body of the email. What do I have to do to get it to display?
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];
This is the HTML which is to be displayed:
<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>
UPDATE: I don’t think I was clear enough… In the HTML which is displayed in the outgoing message, there should be an image that appears throughout the HTML. I have no problem attaching the image to the message, but it does NOT appear in the HTML, which is where I want it. So clearly attaching the image to the message is not working… (I thought it would).
HTH…
I agree with the base 64 answer. Here was my solution using a common NSData base 64 category.
Just to clarify things, I’ll use your example.
Where ########## is replaced with the data of reading.png after it’s been base 64 encoded.