-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (39 loc) · 1.42 KB
/
Program.cs
File metadata and controls
50 lines (39 loc) · 1.42 KB
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.IO;
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;
namespace AzureSendgridDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Execute().Wait();
}
static async Task Execute()
{
///Store sendgrid key insie environement variable and try accessing it
var apiKey = Environment.GetEnvironmentVariable("sendgridkey");
var client = new SendGridClient(apiKey);
// Create messgae body
var msg = new SendGridMessage()
{
From = new EmailAddress("SachinTest@example.com", "DX Team"),
Subject = "Hello World from the SendGrid CSharp SDK!",
PlainTextContent = "Hello, Email!",
HtmlContent = "<strong>Hello, Email!</strong>"
};
msg.AddTo(new EmailAddress("cloud.hero@domaintext.com", "Cloud Hero"));
using (var fileStream = File.OpenRead("C:\\temp\\test.txt"))
{
var a = fileStream.Name.Split('\\');
var b = a[a.Length - 1];
await msg.AddAttachmentAsync(b, fileStream);
}
/// use this to send message.
var response = await client.SendEmailAsync(msg);
}
}
}