J. Petersen
J. Petersen

Reputation: 59

SendGrid - It's like it does not send email to the customer

It's like I have contact Sendrid to hear about how I may not send email.

That's because I need a username and password to be able to do that.

Sendgrid say on Twitter (PM)

For sending mail through SMTP, you will want to set your host to http://smtp.sendgrid.net . You can then use port 587, 2525 or 25 for TLS connections, and can use either your SendGrid username/password for authentication, or an API key generated on your account.

Code:

var resultMail = await _viewRenderService.RenderToStringAsync("~/Views/Templates/NewPassword.cshtml", viewModel);

var api = Environment.GetEnvironmentVariable("[email protected]");
var client = new SendGridClient(api);
var from = new EmailAddress("[email protected]", "J. Petersen");
var to = new EmailAddress("[email protected]", "Test");
var plainTextContent = Regex.Replace(resultMail, "<[^>]*>", "");
var msg = MailHelper.CreateSingleEmail(from, to, title, plainTextContent: plainTextContent,
                        htmlContent: null);

var resulta = client.SendEmailAsync(msg);

I have looked at Documentation on Sendgrid, and I do not think I'll find that you need to use username and password and port.

It is built in .net core 2.0 - Problems are how can I add my username and password and port to this?

Upvotes: 2

Views: 1057

Answers (1)

RY4N
RY4N

Reputation: 1112

Your using the API not SMTP, Here is the standard smtp

var mailMessage = new MailMessage
{
    From = new MailAddress("[email protected]"),
    Subject = "Hello World",
    Body = "Test email from Send Grid SMTP Settings"
};

mailMessage.To.Add("[email protected]");

var smtpClient = new SmtpClient
{
    Credentials = new NetworkCredential("[email protected]", "Your-Password"),
    Host = "smtp.sendgrid.net",
    Port = 587
};

smtpClient.Send(mailMessage);

Upvotes: 1

Related Questions