Windows 10 IoT Core - UWP - 发送邮件后台

Windows 10 IoT Core - UWP - send email background

如何在 Win10 IoT 应用程序 (UWP) 中为带头应用程序在后台发送电子邮件而不显示电子邮件应用程序?

我看到有 EmailMessage 和 EmailManager class 可用,但这只有:

EmailManager.ShowComposeNewEmailAsync()

Launches the email application with a new message displayed.

您无法在没有用户交互的情况下通过 EmailManager API 发送电子邮件。 您需要使用 SmtpClient 来执行此操作。

像这样:

public static void SendMail(MailMessage Message)
{
    SmtpClient client = new SmtpClient();
    client.Host = "smtp.googlemail.com";
    client.Port = 587;
    client.UseDefaultCredentials = false;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = true;
    client.Credentials = new NetworkCredential("myemail@gmail.com", "password");
    client.Send(Message); 
}

或者最好查看微软示例:Send Email with Attachment in C# from Windows Store Apps - XAML - UWP