nakaji
5/2/2016 - 8:48 AM

Send mail using SendGrid

using System;
using System.Net.Mail;
using SendGrid;

namespace SendGripSample
{
    class Program
    {
        static void Main( string[] args)
        {
            var transportWeb = new SendGrid.Web ("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" );

            var message = new SendGridMessage()
            {
                From = new MailAddress ( "a-nakajima@skynet-sys.co.jp"),
                To = new [] { new MailAddress( "a-nakajima@skynet-sys.co.jp" ) },
                Subject = "テストメール" ,
                Text = "Sendgridからのサンプル.40"
            };
            message.SetSendAt( new DateTime (2016,5,2,17,40,0).ToUniversalTime());

            // Send the email.
            try
            {
                transportWeb.DeliverAsync(message).Wait();
                Console .WriteLine("Email sent to " + message.To.GetValue(0));
                Console .WriteLine(" \n \nPress any key to continue." );
                Console .ReadKey();
            }
            catch (Exception ex)
            {
                Console .WriteLine(ex.Message);
                Console .WriteLine(" \n \nPress any key to continue." );
                Console .ReadKey();
            }
        }
    }
}