-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
privateemail smtp instead of sendgrid
- Loading branch information
Showing
11 changed files
with
101 additions
and
3,449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using ConfigurationManager; | ||
using System; | ||
using System.Net; | ||
using GoogleTracer; | ||
using System.Net.Mail; | ||
using Serilog; | ||
|
||
namespace Services | ||
{ | ||
[Profile] | ||
public class SmtpEmailSender : IEmailSender | ||
{ | ||
private SmtpClient client; | ||
private AppSetting _appSetting; | ||
private readonly ILogger _logger; | ||
|
||
public SmtpEmailSender(AppSetting appSetting, ILogger logger) | ||
{ | ||
_appSetting = appSetting; | ||
_logger = logger; | ||
var host = _appSetting["smtpHost"]; | ||
if (!Convert.ToBoolean(_appSetting["DoNotSendMail"]) || !string.IsNullOrEmpty(host)) | ||
this.client = new SmtpClient() { Host = host, Port = 465, EnableSsl = true, Credentials = new NetworkCredential(_appSetting["smtpUsername"], _appSetting["smtpPassword"]) }; | ||
} | ||
|
||
public string SendInvitationEmail(string email, string code) | ||
{ | ||
if (Convert.ToBoolean(_appSetting["DoNotSendMail"])) | ||
email = _appSetting["testMail"]; | ||
if (email == null) | ||
return "ok"; | ||
var message = new MailMessage(_appSetting["smtpUsername"], email) | ||
{ | ||
IsBodyHtml = true, | ||
Subject = $"Passi code {code}", | ||
Body = "<html><body><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" >" + | ||
"<tr><td>Enter this code in application.</td></tr>" + | ||
$"<tr><td><b>{code}</b></td></tr>" + | ||
"</table></body></html>" | ||
}; | ||
try | ||
{ | ||
client.Send(message); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.Error(e, e.Message); | ||
return "failed"; | ||
} | ||
return "ok"; | ||
} | ||
|
||
public string SendDeletingEmail(string email, string code) | ||
{ | ||
if (Convert.ToBoolean(_appSetting["DoNotSendMail"])) | ||
email = _appSetting["testMail"]; | ||
if (email == null) | ||
return "ok"; | ||
var message = new MailMessage(_appSetting["smtpUsername"], email) | ||
{ | ||
IsBodyHtml = true, | ||
Subject = $"Passi code {code}", | ||
Body = "<html><body><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" >" + | ||
"<tr><td>Enter this code in application.</td></tr>" + | ||
$"<tr><td><b>{code}</b></td></tr>" + | ||
"</table></body></html>" | ||
}; | ||
try | ||
{ | ||
client.Send(message); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.Error(e, e.Message); | ||
return "failed"; | ||
} | ||
return "ok"; | ||
} | ||
} | ||
} |
Oops, something went wrong.