简体   繁体   English

如何在Windows 10 Mail App中打开带有附件的新电子邮件

[英]How to open new email with attachment in Windows 10 Mail App

I am trying to add a feature to my C# / .Net app for a user to email a file. 我正在尝试向我的C#/ .Net应用程序添加功能,以便用户通过电子邮件发送文件。 When a user has Outlook installed, I can successfully use the Outlook interop APIs to do exactly what I want. 当用户安装了Outlook后,我就可以成功使用Outlook互操作API完全执行我想要的操作。 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. 但是,在新安装的Windows 10上,我无法确定如何在默认邮件应用程序(来自Windows应用商店)中打开带有附件的电子邮件。

I have tried: 我试过了:

  1. Using EML files, as per https://stackoverflow.com/a/25586282/2102158 根据https://stackoverflow.com/a/25586282/2102158使用EML文件

    • The Mail app does not register itself to open EML files Mail应用程序不会自行注册以打开EML文件
  2. Using the MAPI32.dll etc. (I used the code from https://github.com/metageek-llc/inSSIDer-2/blob/master/MetaScanner/UnhandledException/MapiMailMessage.cs ) 使用MAPI32.dll等(我使用了来自https://github.com/metageek-llc/inSSIDer-2/blob/master/MetaScanner/UnhandledException/MapiMailMessage.cs的代码)

    • A dialog box pops up saying there is no email program registered. 弹出对话框,提示未注册电子邮件程序。 It seems the mail app does not interact with MAPI 邮件应用似乎无法与MAPI交互
  3. Using mailto: links. 使用mailto:链接。

    • The mail program opens, but it does not respect Attachment= or Attach= parameters 邮件程序将打开,但它不遵循Attachment =或Attach =参数

Also

  • Windows.ApplicationModel.Email.EmailMessage seems to be only availble on phones. Windows.ApplicationModel.Email.EmailMessage似乎仅在电话上可用。

  • I do not want to use SMTP to send the message server side. 我不想使用SMTP发送消息服务器端。

  • 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应用程序关联的MS-UNISTORE_EMAIL:和OUTLOOKMAIL:url方案,它们的行为似乎与mailto相同:

  • There does not seem to be any way to start the Mail app from the command line 似乎没有任何方法可以从命令行启动Mail应用程序

Try this: 尝试这个:

a href='mailto:yourname@domain.com?Subject=yoursubject&Body=yourbody&Attachment=file path '

Or try by using file upload to attach the file in mail: 或者尝试使用文件上传将文件附加到邮件中:

Msg.Attachments.Add(new Attachment(FileUpload1.FileContent, System.IO.Path.GetFileName(FileUpload1.FileName)));

Please try the following example 请尝试以下示例

 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);           
        }

The ShowComposeNewEmailAsny(...) part is the magic part. ShowComposeNewEmailAsny(...)部分是魔术部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Universall应用程序中发送带有附件的电子邮件 - How send email with attachment in windows universall app 如何在默认电子邮件应用程序(外观)上打开新邮件窗口以单击按钮发送电子邮件 - How to Open New Mail Windows on Default Email Application(outlook) to send email on button click 如何在Windows邮件应用程序之类的邮件中获取所有会话电子邮件? - How to get all Conversation Email In Mail Like Windows mail App? 如何在Windows 8.1通用应用程序中发送带有附件的电子邮件 - How send email with attachment in a Windows 8.1 universal app 从C#在Windows桌面电子邮件客户端中打开新的电子邮件窗口 - Open new email window in Windows desktop e-mail client from C# 如何在Windows 10应用商店中打开多个窗口 - How to open multiple windows in a Windows 10 store app 如何打开带有附件的默认电子邮件客户端 - How to open default email client with attachment 打开邮件应用程序而不创建电子邮件草稿 - Open mail app without creating email draft 如何使用C#将收到的邮件作为附件附加到新邮件 - How to attach a received mail as an attachment to a new mail using c# Windows 10中的Html编辑类似于Mail应用程序? - Html editing in Windows 10 similar to Mail app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM