Emailing a C#application

Asked

Viewed 547 times

-1

It is possible to send an email directly from the application C# without having to use a server? If yes, how to do this?

For example, in case the user forgets the password and I want to send a new password directly from Email, how is it possible to do this directly from the application using Windows Forms or WPF in C#.

1 answer

1


If I’m not mistaken, you need a server SMTP, I believe the Internet has some free.

Now, assuming you already have it, it’s pretty easy to send emails:

//Instanciando a classe "MailMessage" 
MailMessage mail = new MailMessage();

//Adicione os emails que você vai mandar a mensagem
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");

//Conteudo do email
mail.Subject = "Eu sou o assunto =)"; //Assunto
mail.Body = "Eu sou o corpo do email, sou mais importante =D"; //Corpo do email

//Enviar o email
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Send(mail);

Remember to use namespace System.Net.Mail.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.