Sending an E-mail c#

Asked

Viewed 34 times

-1

Guys, I need help. I have the following email sending controller, where I send an email for password retrieval. this email will be sent from a simple html I have in the templates folder. My doubt is the following how do I pass user data to that Login, so that at the time of sending arrive that data in the user box.

        GmailEmailService gmail = new GmailEmailService();
        EmailMessage msg = new EmailMessage();

        //ler o caminho do arquivo html
        StreamReader sr = new StreamReader("./Emails/templates/EsqueceuASenha.html");

        msg.Body = sr.ReadToEnd();
        msg.IsHtml = true;
        msg.Subject = "Recuperação de Senha";
        msg.ToEmail = emailPara.EmailRecuperacao;

        gmail.SendEmailMessage(msg);



        return RedirectToAction("Login");

1 answer

1

You need to put some markup to replace the static file value with its dynamic variable.

For example, in your EsqueceuASenha.html

<html>
   <body> 
      <b> Sua nova senha provisórioa é:</b> ##NOVA_SENHA##
   </body>
</html>

In the code-Behind, you replace the ##NOVA_SENHA## for the amount you wish...

GmailEmailService gmail = new GmailEmailService();
EmailMessage msg = new EmailMessage();

//ler o caminho do arquivo html
StreamReader sr = new StreamReader("./Emails/templates/EsqueceuASenha.html");

string htmlBody = sr.ReadToEnd();
htmlBody.Replace("##NOVA_SENHA##","admin1234");

msg.Body = htmlBody;
msg.IsHtml = true;
msg.Subject = "Recuperação de Senha";
msg.ToEmail = emailPara.EmailRecuperacao;

gmail.SendEmailMessage(msg);

return RedirectToAction("Login");

Browser other questions tagged

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