Does not send email retrieval of password by SendGrid

1

I've implemented a class to send password recovery email, but the email is not sent.

Code class 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);
        }
    }
}
    
asked by anonymous 27.09.2016 / 03:59

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.

Try also to implement this other example , more oriented to the new service architecture of SendGrid:

    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());
    }
    
27.09.2016 / 15:03