Search code examples
iosxcodeemailmfmailcomposeviewcontrolleropenurl

Links inside email message body


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?


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:[email protected]?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.