I'm trying to make an app that generates a file and fills all email fields so the user just has to enter the body. I also give the user the possibility to choose between the native iOS email app and the Microsoft Outlook app (if it has it installed).
When I implement this to prepare the email to be sent in native email app I have used MessageUI
framework wich make easy attaching the file, but for Outlook app I have to use an URL Scheme (ms-outlook://
) and it seems that there are no easy way (or a way at all) to attach files.
Does anyone have successfully sent an attachment from another app throught Outlook app?
URL Scheme Attachment Microsoft Outlook app
Asked Answered
Were you able to find any solution? –
Cobbs
Not yet. I've asked outlook team and they told me that they don't support this at the moment unfortunatelly. –
Trusty
I managed to figure out myslef. Should I post the solution here? –
Cobbs
I am posting this answer based on "Something is better than nothing". I know it is not possible to send an email with a pre-attached file using iOS App so I have managed to find a way to, at least, be able to send an image file in the email.
// Create an array of recipients for the email.
NSArray* emailRecipients = @[@"[email protected]", @"[email protected]"];
// Create a mutable string to hold all of the recipient email addresses and add the first one.
NSMutableString* emailTo = [[NSMutableString alloc] initWithString:emailRecipients[0]];
// Loop through all of the email recipients except for the first one.
for (int index = 1; index < emailRecipients.count; index++)
{
// Add a semicolon and then the email address at the current index.
[emailTo appendFormat:@";%@", emailRecipients[index]];
}
// Get the email subject from the subject text field.
NSString *emailSubject = @"Your Email Subject";
// Encode the string for URL.
NSString *encodedSubject = [emailSubject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
// Define your image's size
NSString *htmlBody = (@"<div style=\"width:450px;height:797px;\"><img src=\"http://your_website.com/your_image.jpg\" style=\"width:100%;height:100%;\"></div>");
// Encode the string for URL.
NSString* encodedBody = [htmlBody stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
// See if the subject or body are empty.
if (![emailSubject length] || ![emailBody length])
{
// Exit.
return;
}
// Create a string with the URL scheme and email properties.
NSString *stringURL = [NSString stringWithFormat:@"ms-outlook://compose?to=%@&subject=%@&body=%@", emailTo, encodedSubject, encodedBody];
// Convert the string to a URL.
NSURL *url = [NSURL URLWithString:stringURL];
// Open the app that responds to the URL scheme (should be Outlook).
[[UIApplication sharedApplication] openURL:url];
This sends the image file embedded in the email body easily. You may have to adjust the size according to your image.
Multiple recipients need to be separated by a comma, not a semicolon. I just fixed a bug in my app that was caused by using a semicolon for outlook on iOS instead of a comma. –
Enrika
© 2022 - 2024 — McMap. All rights reserved.