问题
I have following code
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("xyz@live.com"));
email.Subject = "Msg Subject ";
email.Body = "My Msg";
await EmailManager.ShowComposeNewEmailAsync(email);
showComposeNewEmailAsync() launches the email application with above message displayed, but I want to sent the email directly to the user without launching the email application. How can I do it?
As I am new to coding please explain me in details.
回答1:
You have to work with Sockets and implement the SMTP behavior by yourself.
Otherwise you could also use a SMTP client for WinRT. According to the Microsoft Forum this should also work with UWP.
回答2:
Use SMTP client for Windows Store as follows:
First install this Nuget Package:
Install-Package lightbuzz-smtp
Second include namespace
using LightBuzz.SMTP;
Then you can use this code snippet to send email directly from UWP app:
using (SmtpClient client = new SmtpClient("smtp.example.com", 465, false, "SenderEmail@example.com", "YourPassword"))
{
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add(new EmailRecipient("someone1@anotherdomain.com"));
emailMessage.CC.Add(new EmailRecipient("someone2@anotherdomain.com"));
emailMessage.Bcc.Add(new EmailRecipient("someone3@anotherdomain.com"));
emailMessage.Subject = "Subject line of your message";
emailMessage.Body = "This is an email sent from a UWP app!";
await client.SendMailAsync(emailMessage);
}
来源:https://stackoverflow.com/questions/34290921/how-to-send-email-directly-to-user-using-c-sharp-in-windows-10-apps