Skip to content

Instantly share code, notes, and snippets.

@brandonmwest
Created August 18, 2012 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonmwest/3384117 to your computer and use it in GitHub Desktop.
Save brandonmwest/3384117 to your computer and use it in GitHub Desktop.
Adding recipients to the X-SMTPAPI Header with sendgrid-csharp
using System;
using System.Collections.Generic;
using SendGridMail;
using System.Net;
using SendGridMail.Transport;
using System.Net.Mail;
namespace EmailTester
{
class MainClass
{
public static void Main (string[] args)
{
// Create the email object first, then add the properties.
SendGrid myMessage = SendGrid.GetInstance();
var recipients = new List<string>();
//You could loop through your dataset here and add each recipient, up to 1000 recipients per message
recipients.Add("Brandon @ Work <brandon.west@sendgrid.com>");
recipients.Add("Brandon @ Gmail <brawest@gmail.com>");
//We want to add the recipients to the X-SMTPAPI header
myMessage.Header.AddTo(recipients);
//Even though we added recipients to the Header, the envelope must also have a valid recipient
myMessage.AddTo("brawest@gmail.com");
myMessage.From = new MailAddress("brandon@sendgrid.com", "Brandon West");
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World!";
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("xxxxxxxx", "xxxxxxx");
// Create an SMTP transport for sending email.
var transportSMTP = SMTP.GetInstance(credentials);
// Send the email.
transportSMTP.Deliver(myMessage);
}
}
}
@peelmicro
Copy link

Hello Brandon,

I've been testing X-SMTP API and it works great, but I have a problem with
spanish caracters like á or é when I include them in _substitution values
in header. For instance if I include 'Que día más bueno hace' I receive '_Que
d?a m?s bueno hace
'.

SendGrid technical service has told me to use UTF-8 character encoding but I can't see how to do it using your API.

Could you please give any advise for avoiding this?. Thanks in advance.

Regards,

Juan Pablo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment