Skip to content

Commit

Permalink
Merge pull request #502 from hargata/Hargata/mailkit.upgrade
Browse files Browse the repository at this point in the history
fix inefficiencies
  • Loading branch information
hargata committed Apr 25, 2024
2 parents 7c34003 + a6471b8 commit f6139bd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Helper/MailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public OperationResponse NotifyUserForRegistration(string emailAddress, string t
}
string emailSubject = "Your Registration Token for LubeLogger";
string emailBody = $"A token has been generated on your behalf, please complete your registration for LubeLogger using the token: {token}";
var result = SendEmail(emailAddress, emailSubject, emailBody);
var result = SendEmail(new List<string> { emailAddress }, emailSubject, emailBody);
if (result)
{
return new OperationResponse { Success = true, Message = "Email Sent!" };
Expand All @@ -58,7 +58,7 @@ public OperationResponse NotifyUserForPasswordReset(string emailAddress, string
}
string emailSubject = "Your Password Reset Token for LubeLogger";
string emailBody = $"A token has been generated on your behalf, please reset your password for LubeLogger using the token: {token}";
var result = SendEmail(emailAddress, emailSubject, emailBody);
var result = SendEmail(new List<string> { emailAddress }, emailSubject, emailBody);
if (result)
{
return new OperationResponse { Success = true, Message = "Email Sent!" };
Expand All @@ -80,7 +80,7 @@ public OperationResponse NotifyUserForAccountUpdate(string emailAddress, string
}
string emailSubject = "Your User Account Update Token for LubeLogger";
string emailBody = $"A token has been generated on your behalf, please update your account for LubeLogger using the token: {token}";
var result = SendEmail(emailAddress, emailSubject, emailBody);
var result = SendEmail(new List<string> { emailAddress}, emailSubject, emailBody);
if (result)
{
return new OperationResponse { Success = true, Message = "Email Sent!" };
Expand Down Expand Up @@ -119,22 +119,22 @@ public OperationResponse NotifyUserForReminders(Vehicle vehicle, List<string> em
emailBody = emailBody.Replace("{TableBody}", tableBody);
try
{
foreach (string emailAddress in emailAddresses)
{
SendEmail(emailAddress, emailSubject, emailBody);
}
SendEmail(emailAddresses, emailSubject, emailBody);
return new OperationResponse { Success = true, Message = "Email Sent!" };
} catch (Exception ex)
{
return new OperationResponse { Success = false, Message = ex.Message };
}
}
private bool SendEmail(string emailTo, string emailSubject, string emailBody) {
private bool SendEmail(List<string> emailTo, string emailSubject, string emailBody) {
string from = mailConfig.EmailFrom;
var server = mailConfig.EmailServer;
var message = new MimeMessage();
message.From.Add(new MailboxAddress(from, from));
message.To.Add(new MailboxAddress(emailTo, emailTo));
foreach(string emailRecipient in emailTo)
{
message.To.Add(new MailboxAddress(emailRecipient, emailRecipient));
}
message.Subject = emailSubject;

var builder = new BodyBuilder();
Expand All @@ -150,6 +150,7 @@ private bool SendEmail(string emailTo, string emailSubject, string emailBody) {
try
{
client.Send(message);
client.Disconnect(true);
return true;
} catch (Exception ex)
{
Expand Down

0 comments on commit f6139bd

Please sign in to comment.