You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improvement/how to: Use form placeholders in notification recipient and sender email address #198
Maybe it's a good idea to add the possibility to add support for the usages of Form values as Recipient adres and sender e-mail for the notification e-mail. Right now only the Email subject of the notification mail can be set.
For a client I need to change the recipient address dynamically. Could you tell me how to do this?
Thank you for your reply. I just tested it out on our project and found the following:
I want to change the notification address on the fly, the correct value is setup in a string which is loaded from a cookie
When I hookup the BeforeSendMail event I can change the mailmessage, but I can't seem to find a way to just change the internal (notification) e-mail instead on both e-mails.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// Form editor change notification email
FormModel.BeforeSendMail += FormModelOnBeforeSendMail;
}
private void FormModelOnBeforeSendMail(FormModel sender, FormEditorMailCancelEventArgs args)
{
// Not working
//FormModel.BeforeSendMail += (o, e) =>//RoutedEventHandler
//{
// o.EmailNotificationRecipients = rayonEmail;
//};
// set the from address on the email
string rayonEmail = UmbracoLite.Controllers.API.RegionController.StaticGet() != null ? UmbracoLite.Controllers.API.RegionController.StaticGet().TeamMemberEmail : null;
args.MailMessage.DeliveryNotificationOptions = new MailAddress(rayonEmail);
}
public class UmbracoEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// Form editor change notification email
FormModel.BeforeSendMail += FormModelOnBeforeSendMail;
}
private void FormModelOnBeforeSendMail(FormModel sender, FormEditorMailCancelEventArgs args)
{
// set the from address on the email
string rayonEmail = UmbracoLite.Controllers.API.RegionController.StaticGet() != null ? UmbracoLite.Controllers.API.RegionController.StaticGet().TeamMemberEmail : null;
// Only the notification e-mail
if(args.EmailType == "notification")
{
// Only change the notification receivers when field rayon is found in form
if (!string.IsNullOrEmpty(rayonEmail) && sender.AllValueFields().Where(n => n.Name.ToLower().Trim() == "rayon" && n.Type.ToLower() == "custom.objectinfo").Count() == 1)
{
var oldAddresses = args.MailMessage.To.ToList();
if (oldAddresses.Count() > 0)
{
// Remove other enteries
foreach (var address in oldAddresses)
{
args.MailMessage.To.Remove(address); // delete old value from to list
args.MailMessage.CC.Add(address); // set old value as cc list
}
// Set rayon / regio as name
args.MailMessage.To.Add(new MailAddress(rayonEmail));
}
}
}
}
}
Activity
kjac commentedon Nov 28, 2018
Hi @RunnicFusion.
Sorry for the late response. You can hook into
FormModel.BeforeSendMailto manipulate theMailMessageobject before it's sent.Check #146 for inspiration. The code sample isn't exactly what you're looking for, but it should get you going in the right direction.
RunnicFusion commentedon Dec 4, 2018
Hi kjac,
Thank you for your reply. I just tested it out on our project and found the following:
RunnicFusion commentedon Dec 5, 2018
Found a way to:
kjac commentedon Dec 7, 2018
@RunnicFusion awesome 😄
Looks like you found the
EmailTypeproperty on theFormEditorMailCancelEventArgs👍Can this issue be closed?