-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailNotificationJob.cs
More file actions
63 lines (59 loc) · 1.66 KB
/
EmailNotificationJob.cs
File metadata and controls
63 lines (59 loc) · 1.66 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
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using Quartz;
namespace QuartzImpl
{
public class EmailNotificationJob : IJob
{
public void Execute(IJobExecutionContext context)
{
var emailsToSend = GetEmailsToSend();
foreach (var email in emailsToSend)
{
SendEmail(email);
}
}
private static void SendEmail(Email email)
{
try
{
var mail = new MailMessage("you@yourcompany.com", email.Address);
var client = new SmtpClient
{
Port = 25,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = "smtp.google.com"
};
mail.Subject = email.Subject;
mail.Body = email.Body;
client.Send(mail);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private static IEnumerable<Email> GetEmailsToSend()
{
var list = new List<Email>
{
new Email
{
Address = "ibrahimozgon@gmail.com",
Body = "Test mail",
Subject = "Test Subject"
},
new Email
{
Address = "ibrahim.ozgon@gmail.com",
Body = "Test mail 2",
Subject = "Test Subject 2"
}
};
return list;
}
}
}