Sending email without and with HTML formatting in Objective-C

November 16, 2009 § Leave a comment

This is the standard of sending email in Objective-C iPhone App.

Use a mailto url + stringByAddingPercentEscapesUsingEncoding + HTML.

Simple Email without any sentences or any HTML formatting:

NSURL *url = [[NSURL alloc] initWithString;@””];
[[UIApplication sharedApplication] openURL:url];

Email with HTML formatting:

NSString *emailBody = @”<table>
<tr><td style=’text-align:right’><b>FirstName</b>:</td>
<td style=’text-align:right’><b>LastName</b>:</td><td>Jackson</td></tr>
<tr><td style=’text-align:right’>
NSString *encodedBody =
[emailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString =
[NSString stringWithFormat:@””, encodedBody];
NSURL *url = [[NSURL alloc] initWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

iPhone simulator does not have a You can only email url in device. However, you can consider to use compiler statements to create specific simulator/device code. You can use UIAlertView to preview the email string. Consider using UITextView to preview the text and UIWebView to preview HTML in the simulator.

    //compiler specific code
    // device specific code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Sending email without and with HTML formatting in Objective-C at Web Builders.


%d bloggers like this: