Reputation: 91
The code I'm using looks just like so many examples But "Web" is an undefined type. Even ReSharper can't tell me where to find it. Do I need another reference with a using or has 'Web' been renamed in v 9.9.0?
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new EmailAddress("[email protected]", "Fff
Lll");
myMessage.Subject = message.Subject;
myMessage.PlainTextContent = message.Body;
myMessage.HtmlContent = message.Body;
var credentials = new NetworkCredential(
ConfigurationManager.AppSettings["mailAccount"],
ConfigurationManager.AppSettings["mailPassword"]
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
Upvotes: 3
Views: 1349
Reputation: 5962
You are following the V2 api documentation which is now obsolete . You can use the V3 api SDK instead . The sample code is like below
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
var client = new SendGridClient(apiKey);
var from = new EmailAddress("[email protected]", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("[email protected]", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
you need to refer the below namespaces
using SendGrid;
using SendGrid.Helpers.Mail;
you can also send the mail without the mail helper class . Follow the below link for more usage and demo
https://github.com/sendgrid/sendgrid-csharp/blob/master/USE_CASES.md
Nuget link :
https://www.nuget.org/packages/Sendgrid/
Upvotes: 4