0

Hi I'm using MFMailComposer to send mail in my application, where i'm attaching an image and in body html content is there and finally i'm adding Thanks,Regards message to mail but all the text content including thanks,Regards is coming as one set then followed by my image attachment then sent from my iPhone signature text is coming. I want to place thanks,regards text before sent from my iPhone signature text,how can i achieve this?

madhead
  • 25,830
  • 14
  • 131
  • 174
Graham Bell
  • 1,109
  • 1
  • 13
  • 30

1 Answers1

3

I have used NSData+Base64 by Matt Gallagher for converting image into base64 so add in your project:

Firstly create emailBody like this:

NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"] ;

[emailBody appendString:@"<p>Check Attachment</p>"];
UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
 //Convert the image into data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
 //Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
 //Add the encoded string to the emailBody string
 //Don't forget the "<b>" tags are required, the "<p>" tags are optional
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
 //You could repeat here with more text or images, otherwise
[emailBody appendString:[NSString stringWithFormat:@"<p><b>%@</b></p>",yourString]];// yourString after image here
 //close the HTML formatting
[emailBody appendString:@"</body></html>"];

Use like this

   [MFMailDialog setMessageBody:emailBody isHTML:YES];

Credit goes to this answer.

Community
  • 1
  • 1
Paresh Navadiya
  • 37,381
  • 10
  • 77
  • 128