Skip to content

Instantly share code, notes, and snippets.

@grebett
Last active May 18, 2017 09:38
Show Gist options
  • Save grebett/b18d1aeb3b1af12442c5493db2413415 to your computer and use it in GitHub Desktop.
Save grebett/b18d1aeb3b1af12442c5493db2413415 to your computer and use it in GitHub Desktop.
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
class Program
{
/// <summary>
/// This calls sends an email to one recipient.
/// </summary>
static void Main(string[] args)
{
RunAsync().Wait();
}
static async Task RunAsync()
{
MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
MailjetRequest request = new MailjetRequest
{
Resource = Send.Resource,
}
.Property(Send.FromEmail, "pilot@mailjet.com")
.Property(Send.FromName, "Mailjet Pilot")
.Property(Send.Subject, "Your email flight plan!")
.Property(Send.TextPart, "Dear passenger, welcome to Mailjet! May the delivery force be with you!")
.Property(Send.HtmlPart, "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!")
.Property(Send.Recipients, new JArray {
new JObject {
{"Email", "passenger@mailjet.com"}
}
});
MailjetResponse response = await client.PostAsync(request);
if (response.IsSuccessStatusCode)
{
Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
Console.WriteLine(response.GetData());
}
else
{
Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment