我正在尝试为Windows Phone Universal App编写电子邮件发送代码。这是我在事件处理程序中编写的代码:
Windows.ApplicationModel.Email.EmailMessage email = new Windows.ApplicationModel.Email.EmailMessage();
email.Subject = "Good morning";
email.Body = "Hello, how are you?";
var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address);
email.To.Add(emailRecipient);
await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(email);
此代码适用于我的Windows Phone 8.1 App。但它没有在通用应用程序中工作。我要添加任何参考吗?有没有办法让它在Universal应用程序中运行?
非常感谢。 :)
答案 0 :(得分:8)
在Windows应用商店应用中,不支持Windows.ApplicationModel.Email命名空间。
请参阅EmailMessage class in MSDN。
您可以使用 mailto 协议发送邮件,并使用 LaunchUriAsync 方法。像这样:
await Launcher.LaunchUriAsync(
new Uri(
"mailto:someemail@somedomain.com?subject=SomeSubject&body=mail content"
));
答案 1 :(得分:1)
在UWP开发中,许多代码仍与Windows Phone 8.1 / Windows Store App相同。如下所示,发送附带附件的电子邮件。
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("test@developerpublish.com"));
email.Subject = "Blog pos`enter code here`t by @isenthil";
var file = await GetTextFile();
email.Attachments.Add(new EmailAttachment(file.Name, file));
await EmailManager.ShowComposeNewEmailAsync(email);