-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (46 loc) · 1.64 KB
/
Program.cs
File metadata and controls
57 lines (46 loc) · 1.64 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
51
52
53
54
55
56
57
using System;
using System.IO;
using System.Net;
using System.Net.Mail;
namespace AzureMailJetDemo
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Hello World!");
// Insert your mailjet account key
String APIKey = "MailJetAPIKey";
// Insert your mailjet SecretKey
String SecretKey = "MailJetSecretKey";
// From address/domain should be validated in Mailjet
String From = "you@example.com";
// Receiver address
String To = "myname@mydomain.com";
//Create new message
MailMessage msg = new MailMessage();
msg.From = new MailAddress(From);
msg.To.Add(new MailAddress(To));
msg.Subject = "Your mail from Mailjet";
msg.Body = "Your mail from Mailjet, sent by C#.";
// Create new attachment and add to message
Attachment att = new Attachment("c:\\temp\\test.txt");
msg.Attachments.Add(att);
// Insert host name and port from Mailject Azure settings.
SmtpClient client = new SmtpClient("in-v3.mailjet.com", 587);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(APIKey, SecretKey);
// send email
client.Send(msg);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
}
}