Fixes: U4-3830 Unable to get email notifications working in version 7
This commit is contained in:
@@ -320,8 +320,13 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var sender = new SmtpClient();
|
||||
sender.Send(mail);
|
||||
using (mail)
|
||||
{
|
||||
using (var sender = new SmtpClient())
|
||||
{
|
||||
sender.Send(mail);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
45
src/Umbraco.Web/NotificationServiceExtensions.cs
Normal file
45
src/Umbraco.Web/NotificationServiceExtensions.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
internal static class NotificationServiceExtensions
|
||||
{
|
||||
internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, ApplicationContext applicationContext)
|
||||
{
|
||||
if (global::Umbraco.Web.UmbracoContext.Current == null) return;
|
||||
service.SendNotification(entity, action, global::Umbraco.Web.UmbracoContext.Current);
|
||||
}
|
||||
|
||||
internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext)
|
||||
{
|
||||
if (umbracoContext == null) return;
|
||||
service.SendNotification(entity, action, umbracoContext, umbracoContext.Application);
|
||||
}
|
||||
|
||||
internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
|
||||
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
|
||||
|
||||
var user = umbracoContext.Security.CurrentUser;
|
||||
applicationContext.Services.NotificationService.SendNotifications(
|
||||
user,
|
||||
entity,
|
||||
action.Letter.ToString(CultureInfo.InvariantCulture),
|
||||
ui.Text("actions", action.Alias),
|
||||
umbracoContext.HttpContext,
|
||||
(mailingUser, strings) => ui.Text("notifications", "mailSubject", strings, mailingUser),
|
||||
(mailingUser, strings) => UmbracoConfig.For.UmbracoSettings().Content.DisableHtmlEmail
|
||||
? ui.Text("notifications", "mailBody", strings, mailingUser)
|
||||
: ui.Text("notifications", "mailBodyHtml", strings, mailingUser));
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/Umbraco.Web/Strategies/NotificationsHandler.cs
Normal file
71
src/Umbraco.Web/Strategies/NotificationsHandler.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
|
||||
namespace Umbraco.Web.Strategies
|
||||
{
|
||||
/// <summary>
|
||||
/// Subscribes to the relavent events in order to send out notifications
|
||||
/// </summary>
|
||||
public sealed class NotificationsHandler : ApplicationEventHandler
|
||||
{
|
||||
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
base.ApplicationStarted(umbracoApplication, applicationContext);
|
||||
|
||||
//Send notifications for the published action
|
||||
ContentService.Published += (sender, args) =>
|
||||
args.PublishedEntities.ForEach(
|
||||
content =>
|
||||
applicationContext.Services.NotificationService.SendNotification(
|
||||
content, ActionPublish.Instance, applicationContext));
|
||||
|
||||
//Send notifications for the update and created actions
|
||||
ContentService.Saved += (sender, args) =>
|
||||
{
|
||||
//need to determine if this is updating or if it is new
|
||||
foreach (var entity in args.SavedEntities)
|
||||
{
|
||||
var dirty = (IRememberBeingDirty) entity;
|
||||
if (dirty.WasPropertyDirty("Id"))
|
||||
{
|
||||
//it's new
|
||||
applicationContext.Services.NotificationService.SendNotification(
|
||||
entity, ActionNew.Instance, applicationContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
//it's updating
|
||||
applicationContext.Services.NotificationService.SendNotification(
|
||||
entity, ActionUpdate.Instance, applicationContext);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Send notifications for the delete action
|
||||
ContentService.Deleted += (sender, args) =>
|
||||
args.DeletedEntities.ForEach(
|
||||
content =>
|
||||
applicationContext.Services.NotificationService.SendNotification(
|
||||
content, ActionDelete.Instance, applicationContext));
|
||||
|
||||
//Send notifications for the unpublish action
|
||||
ContentService.UnPublished += (sender, args) =>
|
||||
args.PublishedEntities.ForEach(
|
||||
content =>
|
||||
applicationContext.Services.NotificationService.SendNotification(
|
||||
content, ActionUnPublish.Instance, applicationContext));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -338,6 +338,7 @@
|
||||
<Compile Include="Models\TagModel.cs" />
|
||||
<Compile Include="Models\UpgradeCheckResponse.cs" />
|
||||
<Compile Include="Models\PasswordChangedModel.cs" />
|
||||
<Compile Include="NotificationServiceExtensions.cs" />
|
||||
<Compile Include="PropertyEditors\ColorListPreValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\EmailAddressPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ListViewPropertyEditor.cs" />
|
||||
@@ -407,6 +408,7 @@
|
||||
<Compile Include="Routing\UrlProviderExtensions.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearCsrfCookiesAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearMediaXmlCacheForDeletedItemsAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\NotificationsHandler.cs" />
|
||||
<Compile Include="TagQuery.cs" />
|
||||
<Compile Include="Trees\CoreTreeAttribute.cs" />
|
||||
<Compile Include="Trees\DataTypeTreeController.cs" />
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Web.SessionState;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using Umbraco.Web;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
@@ -32,9 +33,9 @@ namespace umbraco.dialogs
|
||||
int docId;
|
||||
if (int.TryParse(Request.QueryString["id"], out docId))
|
||||
{
|
||||
|
||||
//TODO Send to publish!!
|
||||
|
||||
//send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
|
||||
ApplicationContext.Services.NotificationService.SendNotification(
|
||||
ApplicationContext.Services.ContentService.GetById(docId), ActionToPublish.Instance, ApplicationContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Web;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
@@ -191,22 +195,15 @@ namespace umbraco.presentation.translation
|
||||
if (t != null)
|
||||
{
|
||||
//user auth and content node validation
|
||||
if (t.Node.Id == int.Parse(taskNode.Attributes.GetNamedItem("id").Value) && (t.User.Id == base.getUser().Id || t.ParentUser.Id == base.getUser().Id))
|
||||
if (t.Node.Id == int.Parse(taskNode.Attributes.GetNamedItem("id").Value) && (t.User.Id == UmbracoUser.Id || t.ParentUser.Id == UmbracoUser.Id))
|
||||
{
|
||||
|
||||
// update node contents
|
||||
var d = new Document(t.Node.Id);
|
||||
Document.Import(d.ParentId, getUser(), (XmlElement)taskNode);
|
||||
Document.Import(d.ParentId, UmbracoUser, (XmlElement)taskNode);
|
||||
|
||||
/* d.Text = taskNode.Attributes.GetNamedItem("nodeName").Value.Trim();
|
||||
|
||||
// update data elements
|
||||
foreach (XmlNode data in taskNode.SelectNodes("data"))
|
||||
if (data.FirstChild != null)
|
||||
d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = data.FirstChild.Value;
|
||||
else
|
||||
d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = "";
|
||||
*/
|
||||
//send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
|
||||
ApplicationContext.Services.NotificationService.SendNotification(d.Content, ActionTranslate.Instance, ApplicationContext);
|
||||
|
||||
t.Closed = true;
|
||||
t.Save();
|
||||
|
||||
@@ -7,8 +7,12 @@ using System.Linq;
|
||||
using System.Web.Script.Services;
|
||||
using System.Web.Services;
|
||||
using System.Xml;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.WebServices;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.BusinessLogic;
|
||||
@@ -160,12 +164,16 @@ namespace umbraco.presentation.webservices
|
||||
if (parentNode != null)
|
||||
content.SortNodes(ref parentNode);
|
||||
|
||||
//send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
|
||||
ApplicationContext.Services.NotificationService.SendNotification(contentService.GetById(parentId), ActionSort.Instance, UmbracoContext, ApplicationContext);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<nodeSorter>("Could not update content sort order", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
Reference in New Issue
Block a user