Does not send email password recovery by Sendgrid

Asked

Viewed 154 times

1

I implemented a class for sending password recovery email, but the email is not sent.

Class code sends email:

public static Task EnviaEmail(string email, string assunto, string mensagem)
    {
        var MinhaMensagem = new SendGridMessage();
        MinhaMensagem.AddTo(email);
        MinhaMensagem.From = new MailAddress("meuemail", "meunome");
        MinhaMensagem.Subject = assunto;
        MinhaMensagem.Text = mensagem;
        MinhaMensagem.Html = mensagem;
        var credenciais = new NetworkCredential("meunomedeusuario", "minhasenha");
        var transporteWeb = new Web(credenciais);

        if(transporteWeb != null)
        {
            return transporteWeb.DeliverAsync(MinhaMensagem);
        }
        else
        {
            return Task.FromResult(0);
        }
    }
}
  • 2

    What tests were done? Did you do it on a neutral server? Did you check if it was not considered spam? In the current form it seems that we have no way to even know if it is a programming problem. You have to provide enough information to ensure that the problem can be solved by us here or only you can solve. It may be programming problem and not even be in this stretch. Já fez um [mcve]?

1 answer

2

This version of your code does not work with credentials. Instead of passing user and password (as in the old method), directly pass the Key API.

Also try to implement this other example, more oriented to the new Sendgrid service architecture:

    public static Task EnviaEmail(string email, string assunto, string mensagem)
    {
        string apiKey = ConfigurationManager.AppSettings['SendGridApiKey'].ToString();
        dynamic sg = new SendGridAPIClient(apiKey);

        Email from = new Email("[email protected]");
        Email to = new Email(email);
        Content content = new Content("text/plain", mensagem);
        Mail mail = new Mail(from, assunto, to, content);

        dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
    }
  • On the sengrid site is not enabling me to generate a key, I do not know the reason, there is some other way ?

  • I don’t think so. I couldn’t find more examples with credential authentication.

  • So there is a problem, if your user registers an outlook email or Hotmail he will not receive anything in his mailbox, because the email is as blocked, because of that I am trying to find another tool that replaces Sendgrid!

  • @Wpfan I think it would be the case to report the problem to Sendgrid.

Browser other questions tagged

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