-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailHelper.cs
55 lines (47 loc) · 1.42 KB
/
EmailHelper.cs
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
using NLog;
using System;
using System.Net;
using System.Net.Mail;
namespace CoinbaseBot
{
public class EmailHelper
{
public static Logger logger = LogManager.GetCurrentClassLogger();
public static bool SendEmail(string emailStmp, string passwordSmtp, string emailReceiver, string subject, string messageBody, string smtpHost, int smtpPort)
{
bool didSend = false;
try
{
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(emailStmp);
message.To.Add(emailStmp);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = messageBody;
using (SmtpClient smtpClient = new SmtpClient())
{
smtpClient.UseDefaultCredentials = true;
smtpClient.Host = smtpHost;
smtpClient.Port = smtpPort;
smtpClient.EnableSsl = true;
smtpClient.Credentials = new System.Net.NetworkCredential(emailStmp, passwordSmtp);
smtpClient.Send(message);
}
}
didSend = true;
}
catch(Exception ex)
{
logger.Error(ex.Message);
if(ex.InnerException != null)
logger.Error(ex.InnerException.ToString());
if (ex.StackTrace != null)
logger.Error(ex.StackTrace);
if (ex.Source != null)
logger.Error(ex.Source);
}
return didSend;
}
}
}