URL Scheme 附件 Microsoft Outlook 应用程序 [英] URL Scheme Attachment Microsoft Outlook app

查看:35
本文介绍了URL Scheme 附件 Microsoft Outlook 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个生成文件并填写所有电子邮件字段的应用程序,以便用户只需输入正文.我还让用户可以在本机 iOS 电子邮件应用程序和 Microsoft Outlook 应用程序(如果已安装)之间进行选择.
当我实现这个以准备要在本机电子邮件应用程序中发送的电子邮件时,我使用了 MessageUI 框架,它可以轻松附加文件,但对于 Outlook 应用程序,我必须使用 URL Scheme (ms-outlook://) 并且似乎没有简单的方法(或根本没有方法)来附加文件.
有没有人通过 Outlook 应用从另一个应用成功发送附件?

解决方案

我根据有总比没有好"来发布这个答案.我知道不可能使用 iOS 应用程序发送带有预附加文件的电子邮件,所以我设法找到了一种方法,至少能够在电子邮件中发送图像文件.

//创建电子邮件的收件人数组.NSArray* emailRecipients = @[@"example@email.com", @"example2@email.com"];//创建一个可变字符串来保存所有收件人电子邮件地址并添加第一个.NSMutableString* emailTo = [[NSMutableString alloc] initWithString:emailRecipients[0]];//遍历除第一个之外的所有电子邮件收件人.for (int index = 1; index < emailRecipients.count; index++){//添加一个分号,然后添加当前索引处的电子邮件地址.[emailTo appendFormat:@";%@", emailRecipients[index]];}//从主题文本字段中获取电子邮件主题.NSString *emailSubject = @"你的邮件主题";//编码 URL 的字符串.NSString *encodedSubject = [emailSubject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];//定义图像的大小NSString *htmlBody = (@"<div style="width:450px;height:797px;"><img src="http://your_website.com/your_image.jpg" style="宽度:100%;高度:100%;">

");//编码 URL 的字符串.NSString* encodingBody = [htmlBody stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];//查看主题或正文是否为空.if (![emailSubject 长度] || ![emailBody 长度]){//出口.返回;}//创建一个带有 URL 方案和电子邮件属性的字符串.NSString *stringURL = [NSString stringWithFormat:@"ms-outlook://compose?to=%@&subject=%@&body=%@", emailTo,encodedSubject,encodedBody];//将字符串转换为 URL.NSURL *url = [NSURL URLWithString:stringURL];//打开响应 URL 方案的应用程序(应该是 Outlook).[[UIApplication sharedApplication] openURL:url];

这很容易发送嵌入在电子邮件正文中的图像文件.您可能需要根据您的图片调整大小.

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?

解决方案

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 = @[@"example@email.com", @"example2@email.com"];

// 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.

这篇关于URL Scheme 附件 Microsoft Outlook 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆