Fixed Monitor Mailer Issue and added debug logs
This commit is contained in:
parent
fb073a6dca
commit
bcaac92e34
|
|
@ -555,6 +555,7 @@ public class Controller : ControllerBase
|
||||||
if (!mail_success)
|
if (!mail_success)
|
||||||
{
|
{
|
||||||
Db.GetSession(authToken).Delete(newUser);
|
Db.GetSession(authToken).Delete(newUser);
|
||||||
|
return StatusCode(500, "Welcome email failed to send");
|
||||||
}
|
}
|
||||||
|
|
||||||
return mail_success ? newUser.HidePassword():Unauthorized();
|
return mail_success ? newUser.HidePassword():Unauthorized();
|
||||||
|
|
|
||||||
|
|
@ -296,8 +296,10 @@ public static partial class Db
|
||||||
await user.SendNewUserWelcomeMessage();
|
await user.SendNewUserWelcomeMessage();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Welcome email failed for {user.Email}");
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,27 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using MailKit.Net.Smtp;
|
using MailKit.Net.Smtp;
|
||||||
|
using MailKit.Security;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
|
|
||||||
namespace InnovEnergy.Lib.Mailer;
|
namespace InnovEnergy.Lib.Mailer;
|
||||||
|
|
||||||
|
|
||||||
public static class Mailer
|
public static class Mailer
|
||||||
{
|
{
|
||||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||||
public static async Task Send(String recipientName, String recipientEmailAddress, String subject, String body)
|
public static async Task Send(string recipientName, string recipientEmailAddress, string subject, string body)
|
||||||
{
|
{
|
||||||
var config = await ReadMailerConfig();
|
var config = await ReadMailerConfig();
|
||||||
|
|
||||||
|
Console.WriteLine("=============== SMTP CONFIG LOADED ==============");
|
||||||
|
Console.WriteLine($"Config full path: {Path.GetFullPath(MailerConfig.DefaultFile)}");
|
||||||
|
Console.WriteLine($"SMTP host: {config!.SmtpServerUrl}");
|
||||||
|
Console.WriteLine($"SMTP port: {config.SmtpPort}");
|
||||||
|
Console.WriteLine($"SMTP username: {config.SmtpUsername}");
|
||||||
|
Console.WriteLine($"Sender: {config.SenderName} <{config.SenderAddress}>");
|
||||||
|
Console.WriteLine("==================================================");
|
||||||
|
|
||||||
|
|
||||||
var from = new MailboxAddress(config!.SenderName, config.SenderAddress);
|
var from = new MailboxAddress(config!.SenderName, config.SenderAddress);
|
||||||
var to = new MailboxAddress(recipientName, recipientEmailAddress);
|
var to = new MailboxAddress(recipientName, recipientEmailAddress);
|
||||||
|
|
||||||
|
|
@ -21,16 +30,24 @@ public static class Mailer
|
||||||
From = { from },
|
From = { from },
|
||||||
To = { to },
|
To = { to },
|
||||||
Subject = subject,
|
Subject = subject,
|
||||||
Body = new TextPart { Text = body }
|
Body = new TextPart("plain") { Text = body }
|
||||||
};
|
};
|
||||||
|
|
||||||
using var smtp = new SmtpClient();
|
using var smtp = new SmtpClient();
|
||||||
|
|
||||||
await smtp.ConnectAsync(config.SmtpServerUrl, config.SmtpPort, false);
|
try
|
||||||
|
{
|
||||||
|
await smtp.ConnectAsync(config.SmtpServerUrl, config.SmtpPort, SecureSocketOptions.StartTls);
|
||||||
await smtp.AuthenticateAsync(config.SmtpUsername, config.SmtpPassword);
|
await smtp.AuthenticateAsync(config.SmtpUsername, config.SmtpPassword);
|
||||||
await smtp.SendAsync(msg);
|
await smtp.SendAsync(msg);
|
||||||
await smtp.DisconnectAsync(true);
|
await smtp.DisconnectAsync(true);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
throw; // keep while testing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)")]
|
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions, CancellationToken)")]
|
||||||
private static async Task<MailerConfig?> ReadMailerConfig()
|
private static async Task<MailerConfig?> ReadMailerConfig()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue