private dynamic TestSendEmail(dynamic arg) { if (this.CurrentUser.HasClaim("admin") == false) { return(403); } var target = (string)arg.body.Value.to; var settings = arg.body.Value.settings; var template = arg.body.Value.template; if (template != null) { MailSenderModule.SendEmail(settings, target, (string)template.Subject, (string)template.Body); } else { MailSenderModule.SendEmail(settings, target, "Test Email From NancyBlack", "Email was sent successfully from <a href=\"" + this.Request.Url + "\">NancyBlack</a>"); } return(200); }
/// <summary> /// Old method signature for compatibility /// </summary> /// <param name="site"></param> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="body"></param> public static void SendEmail(dynamic site, string to, string subject, string body) { MailSenderModule.SendEmail(to, subject, body); }
public void Hook(IPipelines p) { // Use Pipeline Hook so that we can get information about the requests before performing action // with the data p.AfterRequest.AddItemToStartOfPipeline((ctx) => { if (_Events == null) { return; } var siteconfig = ctx.Items["CurrentSite"] as JObject; var user = ctx.CurrentUser as NcbUser; // this will not work when more than one person updating the site at the same time var events = _Events.ToList(); _Events = null; if (siteconfig.Property("watcher") == null) { return; // not configured } var watcher = siteconfig.Property("watcher").Value as JObject; var userIP = ctx.Request.UserHostAddress; Task.Run(() => { foreach (var item in events) { var datatype = watcher.Property(item.DataTypeName.ToLowerInvariant()); if (datatype == null) { continue; } var config = datatype.Value.ToObject <WatcherConfig>(); if (item.Action == "newAttachments") { if (config.autoPrintAttachment == true) { new DataWatcherHub().PrintDocument(item.AffectedRow); } continue; } if (config.version == true) { item.Database.UpsertRecord(new RowVersion() { Action = item.Action, js_Row = JsonConvert.SerializeObject(item.AffectedRow), UserId = user.Id, UserHostAddress = userIP, __createdAt = DateTime.Now, RowId = (int)item.AffectedRow.Id, DataType = item.DataTypeName }); } var emailConfig = config[item.Action]; if (emailConfig != null) { var autoGenPdfConfig = emailConfig.autoGeneratePDF; if (autoGenPdfConfig != null && autoGenPdfConfig.enable == true) { Object dataToClient = new { config = autoGenPdfConfig, data = item.AffectedRow, }; new DataWatcherHub().GenPDFandUpload(dataToClient); } if (emailConfig.enable) { var subject = Razor.Parse <DatabaseEvent>(emailConfig.emailSubject, item); var body = Razor.Parse <DatabaseEvent>(emailConfig.emailTemplate, item); MailSenderModule.SendEmail(emailConfig.sendTo, subject, body); } } } }); }); }