iOS - Is it possible to add clickable urls and also add an attachment in a 3rd party mail client?

51 Views Asked by At

From iOS app, trying to open a mail client (other than iOS mail), and send a message with clickable links. Is it possible to send the message with clickable links and a file attachment?

We tried using mailto which doesn't seem to allow clickable links and attachments. I was wondering if there is another method to achieve this. Note that we can not use MFMailComposeViewController because we want to let the user use a different mail client such as outlook.

As a reference, here is the code. The link in the mail body isn't clickable.

  • (NSString *)mailTofunction:(NSString *)title message:(NSString *)message recipients:(NSArray<NSString *> *)recipients BCCRecipients:(NSArray<NSString *> *)BCCRecipients {

    NSString *mailto = @"mailto:"; NSString *recipient = recipients.firstObject;

    if (0 < recipient.length) { mailto = [mailto stringByAppendingString:recipient]; } if (0 < title.length) { mailto = [mailto stringByAppendingString:[NSString stringWithFormat:@"?subject=%@", title]]; }

    NSMutableArray<NSString *> *BCC;

    if (1 < recipients.count) { BCC = [NSMutableArray arrayWithArray:recipients]; [BCC removeObjectAtIndex:0]; [BCC addObjectsFromArray:BCCRecipients]; }

    if (0 < BCC.count) { NSString *BCCString = [BCC componentsJoinedByString:@";"]; mailto = [mailto stringByAppendingString:[NSString stringWithFormat:@"&bcc=%@", BCCString]]; }

    NSString *bodyText =@""; bodyText = [bodyText stringByAppendingString:@""]; bodyText = [bodyText stringByAppendingString:@""]; bodyText = [bodyText stringByAppendingString:@"<a href="http://www.devaski.com">My blog"]; bodyText = [bodyText stringByAppendingString:@""];

    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[bodyText dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil]; NSString *plainString = attributedString.string; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<[^>]+>" options:NSRegularExpressionCaseInsensitive error:nil]; NSString *emailBody = [regex stringByReplacingMatchesInString:plainString options:0 range:NSMakeRange(0, [plainString length]) withTemplate:@""]; mailto = [mailto stringByAppendingString:[NSString stringWithFormat:@"&body=%@", emailBody]]; return mailto; }

output

For example. Myblog is displayed in Outlook without any clickable links. Is it possible to add a clickable link [sample outlook message (https://i.stack.imgur.com/D6QlC.jpg)

0

There are 0 best solutions below