我正在尝试制作一个应用程序来生成文件并填充所有电子邮件字段,以便用户只需输入正文即可。我还为用户提供了在本机 iOS 电子邮件应用程序和 Microsoft Outlook 应用程序(如果已安装)之间进行选择的可能性。
当我实现此操作以准备要在本机电子邮件应用程序中发送的电子邮件时,我使用了MessageUI
框架可以轻松附加文件,但对于 Outlook 应用程序,我必须使用 URL 方案(ms-outlook://
)并且似乎没有简单的方法(或根本没有方法)来附加文件。
有人通过 Outlook 应用程序从另一个应用程序成功发送了附件吗?
我基于“有总比没有好”来发布这个答案。我知道不可能使用 iOS 应用程序发送带有预附加文件的电子邮件,因此我设法找到一种方法,至少能够在电子邮件中发送图像文件。
// 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];
这样可以轻松发送嵌入电子邮件正文中的图像文件。您可能需要根据您的图像调整尺寸。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)