Question

I need to modify an existing project. In this project there are several (many) places where the app sends an email with preset text within it. The used function is

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailString]];

Which obviously opens iOS Mail, ready to send the message. Now I need to include links in the body of the messages. Is it possible to do it without switching to MFMailComposeViewController in all that places? How?

Was it helpful?

Solution

Have a look at this document - https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MailLinks.html#//apple_ref/doc/uid/TP40007892-SW1

The short answer, yes, you can pre-populate the body of the message by adding a body parameter to the URL (i.e mailto:john@apple.com?body=This%20goes%20to%20body). Notice though, that the string has to be properly escaped, which you can do easily with the help of NSString's stringByAddingPercentEscapesUsingEncoding:

I assume that any URL in the body that looks like a URL will be converted into a link by Mail app itself - not sure about that, test it out.

OTHER TIPS

it is very simple. Each html tag should appended, use front slash before double quote in the url beginning and end
Example :

    NSString *bodyText =@"<html>";
    bodyText = [bodyText stringByAppendingString:@"<head>"];
    bodyText = [bodyText stringByAppendingString:@"</head>"];            
    bodyText = [bodyText stringByAppendingString:@"<body>"];
    bodyText = [bodyText stringByAppendingString:@"<a     href=\"http://www.devaski.com\">My blog"];
    bodyText = [bodyText stringByAppendingString:@"</a>"];
    [mailComposer setMessageBody:bodyText isHTML:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top