mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
This commit is contained in:
parent
205970e4c0
commit
bd5d4a8e92
3 changed files with 50 additions and 2 deletions
|
@ -3,12 +3,59 @@ using System.Threading.Tasks;
|
||||||
using MailKit.Net.Smtp;
|
using MailKit.Net.Smtp;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
using Ombi.Notifications.Models;
|
using Ombi.Notifications.Models;
|
||||||
|
using Ombi.Notifications.Templates;
|
||||||
using Ombi.Settings.Settings.Models.Notifications;
|
using Ombi.Settings.Settings.Models.Notifications;
|
||||||
|
|
||||||
namespace Ombi.Notifications
|
namespace Ombi.Notifications
|
||||||
{
|
{
|
||||||
public class GenericEmailProvider : IEmailProvider
|
public class GenericEmailProvider : IEmailProvider
|
||||||
{
|
{
|
||||||
|
public async Task SendAdHoc(NotificationMessage model, EmailNotificationSettings settings)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
var email = new EmailBasicTemplate();
|
||||||
|
var html = email.LoadTemplate(model.Subject, model.Message, null);
|
||||||
|
|
||||||
|
var body = new BodyBuilder
|
||||||
|
{
|
||||||
|
HtmlBody = html,
|
||||||
|
//TextBody = model.Other["PlainTextBody"]
|
||||||
|
};
|
||||||
|
|
||||||
|
var message = new MimeMessage
|
||||||
|
{
|
||||||
|
Body = body.ToMessageBody(),
|
||||||
|
Subject = model.Subject
|
||||||
|
};
|
||||||
|
message.From.Add(new MailboxAddress(settings.Sender, settings.Sender));
|
||||||
|
message.To.Add(new MailboxAddress(model.To, model.To));
|
||||||
|
|
||||||
|
using (var client = new SmtpClient())
|
||||||
|
{
|
||||||
|
client.Connect(settings.Host, settings.Port); // Let MailKit figure out the correct SecureSocketOptions.
|
||||||
|
|
||||||
|
// Note: since we don't have an OAuth2 token, disable
|
||||||
|
// the XOAUTH2 authentication mechanism.
|
||||||
|
client.AuthenticationMechanisms.Remove("XOAUTH2");
|
||||||
|
|
||||||
|
if (settings.Authentication)
|
||||||
|
{
|
||||||
|
client.Authenticate(settings.Username, settings.Password);
|
||||||
|
}
|
||||||
|
//Log.Info("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated);
|
||||||
|
await client.SendAsync(message);
|
||||||
|
await client.DisconnectAsync(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//Log.Error(e);
|
||||||
|
throw new InvalidOperationException(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Send(NotificationMessage model, EmailNotificationSettings settings)
|
public async Task Send(NotificationMessage model, EmailNotificationSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -7,5 +7,6 @@ namespace Ombi.Notifications
|
||||||
public interface IEmailProvider
|
public interface IEmailProvider
|
||||||
{
|
{
|
||||||
Task Send(NotificationMessage model, EmailNotificationSettings settings);
|
Task Send(NotificationMessage model, EmailNotificationSettings settings);
|
||||||
|
Task SendAdHoc(NotificationMessage model, EmailNotificationSettings settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -446,11 +446,11 @@ namespace Ombi.Controllers
|
||||||
|
|
||||||
var url =
|
var url =
|
||||||
$"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";
|
$"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}";
|
||||||
await EmailProvider.Send(new NotificationMessage
|
await EmailProvider.SendAdHoc(new NotificationMessage
|
||||||
{
|
{
|
||||||
To = user.Email,
|
To = user.Email,
|
||||||
Subject = $"{appName} Password Reset",
|
Subject = $"{appName} Password Reset",
|
||||||
Message = $"Hello {user.UserName}, <br/> You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
|
Message = $"You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
|
||||||
$"<a href=\"{url}/token?token={token}\"> Reset </a>"
|
$"<a href=\"{url}/token?token={token}\"> Reset </a>"
|
||||||
}, emailSettings);
|
}, emailSettings);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue