blob: aa8a5a9c9291442e753bd16860db67db06b6a2f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using SendGrid;
namespace Example
{
internal class Program
{
// this code is used for the SMTPAPI examples
private static void Main()
{
// Create the email object first, then add the properties.
var myMessage = new SendGridMessage();
myMessage.AddTo("anna@example.com");
myMessage.From = new MailAddress("john@example.com", "John Smith");
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World! %tag%";
var subs = new List<String> { "私は%type%ラーメンが大好き" };
myMessage.AddSubstitution("%tag%",subs);
myMessage.AddSection("%type%", "とんこつ");
SendAsync(myMessage);
Console.ReadLine();
}
private static async void SendAsync(SendGridMessage message)
{
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
try
{
await transportWeb.DeliverAsync(message);
Console.WriteLine("Sent!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
|