x
I'm sorry, but you have been denied access to edit this topic.
Help get this topic noticed by sharing it on Twitter Twitter, Facebook Facebook, or email.
Shakil Bharucha

Send Grid SMTPAPI implementation in C#

SendGrid can update wiki docs now:

To implement Sendgrid's X-SMTPAPI in C#, we can use the MailMessage class and add headers in it.
See my example:

string headers = "{\"to\":[\"example1@example.com\",\"example2@example.com\",\"example3@example.com\"],\"filters\" : {\"domainkeys\" : {\"settings\" : {\"enable\" : 0}}}}";
//The bellow commented line works for twitter status messages
//string headers = "{\"to\":[\"example@twitterstatus\"],\"filters\" : {\"twitter\" : {\"settings\" : {\"enable\" : \"1\", \"username\" : \"example@gmail.com\",\"password\" : \"password\"}}}}";
MailMessage msg = new MailMessage();
msg.Subject = "Testing Send Grid";
msg.Body = "hello Testing via Send Grid. Its working for twitter also.. Yeppieee!!!!";
msg.From = new MailAddress("alerts@example.com");
msg.To.Add("example@example.com");
msg.Headers.Add("X-SMTPAPI", headers);
msg.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
NetworkCredential basicauthenticationinfo = new NetworkCredential("sendgriduser@example.com", "sendgridpassword");
client.Host = "smtp.sendgrid.net";
client.Port = 25;

client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;

client.Send(msg);

Send grid guys say something about RFC 821 in their api description, but even with long header strings it is working fine. I am unsure on this issue.
Also Note: Sendgrid automatically avoids sending duplicate mails, but counts them in the number of mails sent.
2 people like
this idea
+1
Reply