[英]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: 我试过了:
Using EML files, as per https://stackoverflow.com/a/25586282/2102158 根据https://stackoverflow.com/a/25586282/2102158使用EML文件
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的代码)
Using mailto: links. 使用mailto:链接。
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.