通过 UWP EmailManager 发送电子邮件附件不起作用 [英] Sending email attachments via UWP EmailManager not working

查看:20
本文介绍了通过 UWP EmailManager 发送电子邮件附件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码从通用应用发送附件不起作用,为什么?

 Dim emailMessage As New EmailMessage()emailMessage.[To].Add(New EmailRecipient("a@b.com"))emailMessage.Subject = "测试"emailMessage.Body = "Hello World"Dim localAppFolder = Windows.Storage.ApplicationData.Current.LocalFolderDim file = Await localAppFolder.CreateFileAsync("SomeFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting)等待 Windows.Storage.FileIO.WriteTextAsync(文件,aaaa")Dim fileRef = RandomAccessStreamReference.CreateFromFile(file)emailMessage.Attachments.Add(New EmailAttachment(file.Name, fileRef))等待 EmailManager.ShowComposeNewEmailAsync(emailMessage)

To,主题和正文在 Outlook 中显示正常,但缺少附件:

如果您之前已选择桌面 Outlook 应用程序作为mailto 协议的默认应用程序,则必须更改mailto 的默认应用程序:控制面板中的协议关联.

以前,ShowComposeNewEmailAsync 仅适用于 Windows Phone 运行时应用程序.并且它在文档中不是最新的,因为它不包括对 win 10 的支持.

在 Windows 10 移动版上,它运行良好,没有任何问题.但在 Windows 桌面上,您必须选择商店应用.

Sending an attachment from a universal app with the following code is not working, why?

        Dim emailMessage As New EmailMessage()
        emailMessage.[To].Add(New EmailRecipient("a@b.com"))
        emailMessage.Subject = "Test"
        emailMessage.Body = "Hello World"

        Dim localAppFolder = Windows.Storage.ApplicationData.Current.LocalFolder
        Dim file = Await localAppFolder.CreateFileAsync("SomeFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting)
        Await Windows.Storage.FileIO.WriteTextAsync(file, "aaaa")
        Dim fileRef = RandomAccessStreamReference.CreateFromFile(file)
        emailMessage.Attachments.Add(New EmailAttachment(file.Name, fileRef))
        Await EmailManager.ShowComposeNewEmailAsync(emailMessage)

To, subject and body show fine in Outlook, but the attachment is missing: Outlook screenshot

解决方案

I believe it is because the Outlook is a Desktop app. As I understood, the EmailManager.ShowComposeNewEmailAsync uses mailto: protocal to launch mail client app and use share to provide the email content.

If you choose the mail store app when the select default app dialog launches, you will be able to see the attachment as following:

If you have previously chosen Desktop Outlook app as the default as for mailto protocol, you have to change the default app for the mailto: protocol association in control panel .

Previously, the ShowComposeNewEmailAsync only works for windows phone runtime app. And it is not up-to-date in the document, because it doesn't include the win 10 support.

On Windows 10 mobile, it works well without any problem. But on Windows Desktop, you have to choose a store app.

这篇关于通过 UWP EmailManager 发送电子邮件附件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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