Skip to content

advancedrei/smtpapi-csharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

smtpapi-csharp

Easily Build SendGrid X-SMTPAPI Headers.

This is a beta and method names are likely to change.

using SendGrid.SmtpApi;

var header = new Header();

var uniqueArgs = new Dictionary<string,string> {
  { "foo", "bar" },
  { "chunky", "bacon"}
};

header.AddUniqueArgs(uniqueArgs);

var xmstpapiJson = header.JsonString();

You can then use generated JSON in conjunction with your favorite SMTP library.

SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.sendgrid.net";
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("your_sendgrid_username","your_sendgrid_password");
 
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("[email protected]"));
mail.From = "[email protected]";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";

// add the custom header that we built above
mail.Headers.Add( "X-SMTPAPI", xmstpapiJson );
 
client.SendAsync(mail, null);

For a more complete example, look at the included Example project.

About

Easily Build SendGrid XSMTPAPI Headers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%