How to send email directly to a user using C # in Windows 10 applications?

I have the 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 () starts the email application with the message displayed above, but I want to send an email directly to the user without starting the email application. How can i do this?


Since I am new to coding, please explain to me in more detail.

+4
source share
2 answers

You need to work with Sockets and execute SMTP behavior yourself.


SMTP- WinRT. Microsoft Forum UWP.

+2

SMTP- Windows Store :

Nuget:

Install-Package lightbuzz-smtp

using LightBuzz.SMTP;

UWP:

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

Source: https://habr.com/ru/post/1620122/


All Articles