Sending Email from a C # application [closed]

-1

Is it possible to send an email directly from the C # application without having to use a server? If so, how do you do that?

For example, if the user forgets the password and I want to send a new password directly from the mail, how can I do this directly from the application using Windows Forms or WPF in C #.

    
asked by anonymous 03.07.2017 / 22:20

1 answer

1

If I'm not mistaken, you need a SMTP server , I believe you have some free on the internet.

Now, assuming you already have it, it's very 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 the System.Net.Mail namespace.

    
04.07.2017 / 00:28