feature: expression helpers - basic email sending
This commit is contained in:
@@ -38,9 +38,10 @@ namespace Disco.Services.Expressions
|
||||
public static void InitializeExpressions()
|
||||
{
|
||||
TypeRegistry.RegisterType("DataExt", typeof(Extensions.DataExt));
|
||||
TypeRegistry.RegisterType("UserExt", typeof(Extensions.UserExt));
|
||||
TypeRegistry.RegisterType("DeviceExt", typeof(Extensions.DeviceExt));
|
||||
TypeRegistry.RegisterType("EmailExt", typeof(Extensions.EmailExt));
|
||||
TypeRegistry.RegisterType("ImageExt", typeof(Extensions.ImageExt));
|
||||
TypeRegistry.RegisterType("UserExt", typeof(Extensions.UserExt));
|
||||
}
|
||||
|
||||
public T EvaluateFirst<T>(object ExpressionContext, IDictionary Variables)
|
||||
@@ -297,6 +298,11 @@ namespace Disco.Services.Expressions
|
||||
typeof(Extensions.DeviceExt).AssemblyQualifiedName
|
||||
},
|
||||
|
||||
{
|
||||
"EmailExt",
|
||||
typeof(Extensions.EmailExt).AssemblyQualifiedName
|
||||
},
|
||||
|
||||
{
|
||||
"ImageExt",
|
||||
typeof(Extensions.ImageExt).AssemblyQualifiedName
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.Services.Messaging;
|
||||
using Disco.Services.Messaging;
|
||||
using System;
|
||||
|
||||
namespace Disco.Services.Expressions.Extensions
|
||||
{
|
||||
public static class EmailExt
|
||||
{
|
||||
public static void SendToUser(User user, string subject, string body)
|
||||
{
|
||||
var to = user.EmailAddress;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(to))
|
||||
throw new Exception($"User ({user.UserId}) does not have an email address");
|
||||
|
||||
Send(to, subject, body);
|
||||
}
|
||||
|
||||
public static void Send(string to, string subject, string body)
|
||||
{
|
||||
var email = new Email()
|
||||
{
|
||||
Subject = subject,
|
||||
Body = body,
|
||||
};
|
||||
email.To.Add(to);
|
||||
|
||||
EmailService.SendEmail(email);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user