Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:37:52+00:00 2026-06-02T23:37:52+00:00

I have this code, which is supposed to attach a HTML file to the

  • 0

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:&nbsp;TBM "J" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Elev:&nbsp;19.76<br>Desc:&nbsp;USGS Test Site
 <div>
 <table border class="boldtable">
 <tr BGCOLOR="ADDAFE">
 <th>STA&nbsp;</th>
 <th>BS&nbsp;</th>
 <th>HI&nbsp;</th>
 <th>FS&nbsp;</th>
 <th>ELEV&nbsp;</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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:37:53+00:00Added an answer on June 2, 2026 at 11:37 pm

    I agree with the base 64 answer. Here was my solution using a common NSData base 64 category.

    static NSString *EmailBody(NSString *description, UIImage *image)
    {
        NSString *format = @"<html>"
        @"<body>"
        @"<p>%@</p>"
        @"<p><b><img src='data:image/png;base64,%@'></b></p>"
        @"</body>"
        @"</html>";
        NSData *imageData = UIImagePNGRepresentation(image);    
        return [NSString stringWithFormat:format, description, [imageData base64EncodedString]];
    }
    

    Just to clarify things, I’ll use your example.

    <html>
    <head>
    <link rel='stylesheet' type='text/css' href='default.css'/>
    </head>
     <body>
     STA:&nbsp;TBM "J" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Elev:&nbsp;19.76<br>Desc:&nbsp;USGS Test Site
     <div>
     <table border class="boldtable">
     <tr BGCOLOR="ADDAFE">
     <th>STA&nbsp;</th>
     <th>BS&nbsp;</th>
     <th>HI&nbsp;</th>
     <th>FS&nbsp;</th>
     <th>ELEV&nbsp;</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="data:image/png;base64,##########" align=center></td><td>3.14</td><td valign="middle">22.90</td>
    

    Where ########## is replaced with the data of reading.png after it’s been base 64 encoded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which can display drop down in div tag of html.
I have this code which is supposed to generate a captcha image of random
I have this code which will include template.php file from inside each of these
I have this code which should create a splash image with either no animation
I have the following code which is supposed to be removing a particular email
I have this assembler code, which I'm supposed to translate into machine code in
I have this code that's supposed to unzipp a file. public class dec extends
I have this code which is called at an onChange event of an function
I have this code which gets WP posts, but it gets all the posts
I have this code (which is way simplified from the real code): public interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.