Update to mailkit for better email standard

This commit is contained in:
2025-09-01 10:16:38 -07:00
parent 3e947e8caf
commit 34dca5f57f
5 changed files with 29 additions and 20 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ Server:
Need to update notification email
Create page to notify cx that their work email has been verified
Verify that each resume section belongs to the resume it was created for:
Emails:
Make emails follow theme of website better
Client:
jobs/editor:
+1 -1
View File
@@ -91,7 +91,7 @@ namespace BoredCareers.Controllers {
EmailContents = Substitue(EmailContents, "@ID", CompanyID.ToString());
EmailContents = Substitue(EmailContents, "@VerifyPassword", test.EmailToken);
string result = _emailContext.Send(test.Email, EmailService.CompanyVerifyEmailSubject, EmailContents);
string result = await _emailContext.Send(test.Email, EmailService.CompanyVerifyEmailSubject, EmailContents);
_emailContext._SentEmails.Add(key, DateTime.Now);
return Redirect("/");
}
+1
View File
@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.8" />
<PackageReference Include="MailKit" Version="4.13.0" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="9.4.0" />
<PackageReference Include="Stripe.net" Version="48.2.0" />
@@ -51,7 +51,7 @@ namespace BoredCareers.Services.TimerService {
string emailbody = EmailService.JobAutoClosedBody;
//Substitue(emailbody, "@job", listing.JobListingID);
_em.Send(email, EmailService.JobAutoClosedSubject, emailbody);
await _em.Send(email, EmailService.JobAutoClosedSubject, emailbody);
}
}
@@ -1,4 +1,7 @@
using System.Net.Mail;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;
namespace BoredCareers.Services {
public partial class EmailService {
@@ -17,25 +20,29 @@ namespace BoredCareers.Services {
EmailPassword = _EmailPassword;
}
public string Send( string Destination, string Subject, string Body ) {
using (SmtpClient client = new SmtpClient( EmailServer, EmailPort )){
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential( EmailAddress, EmailPassword );
public async Task<string> Send(string Destination, string Subject, string Body) {
try {
MailMessage msg = new MailMessage(){
IsBodyHtml = true,
Subject = Subject,
Body = Body
};
msg.From = new MailAddress( EmailAddress, "no-reply" );
msg.To.Add( new MailAddress( Destination ) );
client.Send( msg );
return "Success";
MimeMessage message = new MimeMessage();
message.From.Add(new MailboxAddress(EmailAddress.Split('@')[0], EmailAddress));
message.To.Add(new MailboxAddress(Destination.Split('@')[0], Destination));
message.Subject = Subject;
BodyBuilder messageBody = new BodyBuilder();
messageBody.HtmlBody = Body;
message.Body = messageBody.ToMessageBody();
using (SmtpClient client = new SmtpClient()) {
await client.ConnectAsync(EmailServer, EmailPort);
client.Authenticate(new SaslMechanismLogin(EmailAddress, EmailPassword));
string serverResponse = await client.SendAsync(message);
await client.DisconnectAsync(true);
return serverResponse;
}
} catch (Exception e) {
return "An Error Has Occurred Sending Email : " + e.ToString();
}
}
}
}
}