How to override SendRazorEmail to use a custom message like the sendEmail
Hi all.
Using umbraco 7.14.5 and Umbraco Forms 7.4.1.
I would like to be able to add a message to the SendRazorEmail workflow that an editor can edit.
So i tried to override the SendRazorEmail and add a Message attribute. But i cant figure out how to get it into the .cshtml that @inherits UmbracoViewPage<Umbraco.Forms.Core.Models.FormsHtmlModel>
public class SendCustomEmailWorkflow : Umbraco.Forms.Core.Providers.WorkflowTypes.SendRazorEmail
{
public SendCustomEmailWorkflow()
{
this.Name = "Send Custom Email";
this.Id = new Guid("D6A2C406-CF89-11DE-B075-55B055D89593");
this.Description = "Used for designed emails";
}
[Umbraco.Forms.Core.Attributes.Setting("Message", description = "insert a custom message, where {alias} replace data from the field with the alias.", view = "textarea")]
public string Message { get; set; }
}
Maybe there is a way to get this workflow by the forms id?
I manged to do a work around where i made a complete new WorkFlow and used RazorEngine.
Simplified WorkFlow
public class SendCustomEmailWorkflow : WorkflowType
{
public SendCustomEmailWorkflow()
{
this.Name = "Send Custom Email";
this.Id = new Guid("D6A2C406-CF89-11DE-B075-55B055D89593");
this.Description = "Has designed email";
this.Icon = "icon-wand color-green";
}
[Setting("Receiver Email", description = "Enter the receiver email", view = "textfield")]
public string ReceiverEmail { get; set; }
[Setting("Sender Email", description = "Enter the sender email", view = "textfield")]
public string SenderEmail { get; set; }
[Setting("Subject", description = "Enter the subject", view = "textfield")]
public string Subject { get; set; }
[Setting("Message", description = "Enter a message", view = "textarea")]
public string Message { get; set; }
// Could add a template picker here to make it more dynamic.
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
// This is my custom model, where i transform the Record into something like the FormsHtmlModel.
var model = new FormRecordModel(record, this.Message);
// RazorEngine 3.10.0
var viewsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views\\Partials");
var config = new TemplateServiceConfiguration
{
TemplateManager = new ResolvePathTemplateManager(new[] { viewsPath }),
DisableTempFileLocking = true,
};
Engine.Razor = RazorEngineService.Create(config);
var html = Engine.Razor.RunCompile("Custom-Email.cshtml", null, model);
// After this i send the email via SmtpClient
return WorkflowExecutionStatus.Completed;
}
public override List<Exception> ValidateSettings()
{
var list = new List<Exception>();
if (string.IsNullOrEmpty(this.ReceiverEmail))
{
list.Add(new Exception("Reciever Email is required, but is empty"));
}
if (string.IsNullOrEmpty(this.SenderEmail))
{
list.Add(new Exception("Sender Email is required, but is empty"));
}
if (string.IsNullOrEmpty(this.Subject))
{
list.Add(new Exception("Subject is required, but is empty"));
}
if (string.IsNullOrEmpty(this.Message))
{
list.Add(new Exception("Message is required, but is empty"));
}
return list;
}
}
How to override SendRazorEmail to use a custom message like the sendEmail
Hi all.
Using umbraco 7.14.5 and Umbraco Forms 7.4.1.
I would like to be able to add a message to the SendRazorEmail workflow that an editor can edit.
So i tried to override the SendRazorEmail and add a Message attribute. But i cant figure out how to get it into the .cshtml that
@inherits UmbracoViewPage<Umbraco.Forms.Core.Models.FormsHtmlModel>
Maybe there is a way to get this workflow by the forms id?
Do anyone have any idear?
I manged to do a work around where i made a complete new WorkFlow and used RazorEngine.
Simplified WorkFlow
Simplified custom-email.html
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.