juFo juFo -3 years ago 269
C# Question

Windows 10 IoT Core - UWP - send email background

How do you send an email in a Win10 IoT app (UWP) in the background for a headed application without showing an email app?

I see there is an EmailMessage and EmailManager class available but this only has:

EmailManager.ShowComposeNewEmailAsync()



Launches the email application with a new message displayed.

Answer Source

You can't send E-Mail through EmailManager API without user interaction. You need to use SmtpClient to do so.

Like this:

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

Or better check the microsoft example: Send Email with Attachment in C# from Windows Store Apps - XAML - UWP

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download