如何在Windows 10 Mail App中打开带有附件的新电子邮件 [英] How to open new email with attachment in Windows 10 Mail App
问题描述
我正在尝试添加一个功能到我的C#/ .Net应用程序为用户发送电子邮件文件。
当用户安装Outlook时,我可以成功地使用Outlook interop API来完成我想要的操作。
然而,在新的Windows 10安装中,我无法解决如何在Windows Store中的默认Mail应用程序中打开包含附件的电子邮件。
I am trying to add a feature to my C# / .Net app for a user to email a file. When a user has Outlook installed, I can successfully use the Outlook interop APIs to do exactly what I want. However on a new Windows 10 install, I cannot work out how to open an email with an attachment in the default Mail app, which is from the Windows Store.
我试过:
-
使用EML文件,根据 https://stackoverflow.com/a/25586282/2102158
- 邮件应用程式没有注册自己打开EML文件
使用MAPI32.dll等(我使用 https://github.com/metageek-llc/inSSIDer- 2 / blob / master / MetaScanner / UnhandledException / MapiMailMessage.cs )
Using the MAPI32.dll etc. (I used the code from https://github.com/metageek-llc/inSSIDer-2/blob/master/MetaScanner/UnhandledException/MapiMailMessage.cs)
- 弹出一个对话框,说没有电子邮件程序注册。似乎邮件应用程序不与MAPI交互
使用mailto:links。
Using mailto: links.
- 邮件程序打开,但不遵守附件=或附加=参数
另外
-
Windows .ApplicationModel.Email.EmailMessage似乎只能在手机上使用。
Windows.ApplicationModel.Email.EmailMessage seems to be only availble on phones.
我不想使用SMTP发送消息服务器端。
I do not want to use SMTP to send the message server side.
我还尝试了与邮件应用程序相关联的MS-UNISTORE_EMAIL:和OUTLOOKMAIL:url方案,它们似乎与mailto的行为相同:
I also tried the MS-UNISTORE_EMAIL: and OUTLOOKMAIL: url schemes, which are associated to the Mail app, they seemed to behave the same as mailto:
似乎没有办法从命令行启动Mail应用程序
There does not seem to be any way to start the Mail app from the command line
推荐答案
请尝试以下示例
private async void SendEmailButton_Click(object sender, RoutedEventArgs e)
{
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add(new EmailRecipient("***@***.com"));
string messageBody = "Hello World";
emailMessage.Body = messageBody;
StorageFolder MyFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile attachmentFile =await MyFolder.GetFileAsync("MyTestFile.txt");
if (attachmentFile != null)
{
var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
var attachment = new Windows.ApplicationModel.Email.EmailAttachment(
attachmentFile.Name,
stream);
emailMessage.Attachments.Add(attachment);
}
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
ShowComposeNewEmailAsny(...)
part是魔术的一部分。
The ShowComposeNewEmailAsny(...)
part is the magic part.
这篇关于如何在Windows 10 Mail App中打开带有附件的新电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!