-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the email support that was coded at the NDC 2012 Hackathon.
Closes #446
- Loading branch information
1 parent
f798f46
commit 0bb5516
Showing
16 changed files
with
431 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
|
|||
Microsoft Visual Studio Solution File, Format Version 11.00 | |||
# Visual Studio 2010 | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifySample", "NotifySample\NotifySample.csproj", "{58400EA4-C837-434E-B5AC-7540287F7BDE}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
Release|Any CPU = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{58400EA4-C837-434E-B5AC-7540287F7BDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{58400EA4-C837-434E-B5AC-7540287F7BDE}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{58400EA4-C837-434E-B5AC-7540287F7BDE}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{58400EA4-C837-434E-B5AC-7540287F7BDE}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
<?xml version="1.0" encoding="utf-8" ?> | |||
<configuration> | |||
<configSections> | |||
<section name="MessageForwardingInCaseOfFaultConfig" | |||
type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" /> | |||
</configSections> | |||
|
|||
<system.net> | |||
<mailSettings> | |||
<smtp from="X" deliveryMethod="Network"> | |||
<network defaultCredentials="false" | |||
host="smtp.gmail.com" | |||
port="587" | |||
userName="username" | |||
password="pwd" | |||
enableSsl="true" /> | |||
</smtp> | |||
</mailSettings> | |||
</system.net> | |||
|
|||
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" /> | |||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
namespace NotifySample | |||
{ | |||
using System; | |||
using System.Net.Mail; | |||
using NServiceBus; | |||
|
|||
public class EmailSender : IWantToRunAtStartup | |||
{ | |||
public IBus Bus { get; set; } | |||
|
|||
public void Run() | |||
{ | |||
Console.WriteLine("Hit any key to send a email using the notification satellite"); | |||
|
|||
while (Console.ReadKey().Key.ToString().ToLower() != "q") | |||
Bus.SendEmail(new MailMessage("X", "Y", "Hello from the the NSB notification support", "Tha body")); | |||
} | |||
|
|||
public void Stop() | |||
{ | |||
//no-op | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
namespace NotifySample | |||
{ | |||
using NServiceBus; | |||
|
|||
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server | |||
{ | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,65 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
<ProductVersion>8.0.30703</ProductVersion> | |||
<SchemaVersion>2.0</SchemaVersion> | |||
<ProjectGuid>{58400EA4-C837-434E-B5AC-7540287F7BDE}</ProjectGuid> | |||
<OutputType>Library</OutputType> | |||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||
<RootNamespace>NotifySample</RootNamespace> | |||
<AssemblyName>NotifySample</AssemblyName> | |||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |||
<FileAlignment>512</FileAlignment> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\Debug\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\Release\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="log4net"> | |||
<HintPath>..\..\..\binaries\log4net.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus"> | |||
<HintPath>..\..\..\binaries\NServiceBus.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Core"> | |||
<HintPath>..\..\..\binaries\NServiceBus.Core.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Host"> | |||
<HintPath>..\..\..\binaries\NServiceBus.Host.exe</HintPath> | |||
</Reference> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Core" /> | |||
<Reference Include="Microsoft.CSharp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="EmailSender.cs" /> | |||
<Compile Include="EndpointConfig.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="App.config"> | |||
<SubType>Designer</SubType> | |||
</None> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<StartAction>Program</StartAction> | |||
<StartProgram>$(ProjectDir)$(OutputPath)NServiceBus.Host.exe</StartProgram> | |||
</PropertyGroup> | |||
</Project> |
36 changes: 36 additions & 0 deletions
36
Samples/Notifications/NotifySample/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
using System.Reflection; | |||
using System.Runtime.CompilerServices; | |||
using System.Runtime.InteropServices; | |||
|
|||
// General Information about an assembly is controlled through the following | |||
// set of attributes. Change these attribute values to modify the information | |||
// associated with an assembly. | |||
[assembly: AssemblyTitle("NotifySample")] | |||
[assembly: AssemblyDescription("")] | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("")] | |||
[assembly: AssemblyProduct("NotifySample")] | |||
[assembly: AssemblyCopyright("Copyright © 2012")] | |||
[assembly: AssemblyTrademark("")] | |||
[assembly: AssemblyCulture("")] | |||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible | |||
// to COM components. If you need to access a type in this assembly from | |||
// COM, set the ComVisible attribute to true on that type. | |||
[assembly: ComVisible(false)] | |||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM | |||
[assembly: Guid("acf83a72-5535-4a5d-adcc-453aa7c23cf8")] | |||
|
|||
// Version information for an assembly consists of the following four values: | |||
// | |||
// Major Version | |||
// Minor Version | |||
// Build Number | |||
// Revision | |||
// | |||
// You can specify all the values or you can default the Build and Revision Numbers | |||
// by using the '*' as shown below: | |||
// [assembly: AssemblyVersion("1.0.*")] | |||
[assembly: AssemblyVersion("1.0.0.0")] | |||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Notifications/NServiceBus.Notifications/BusExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
namespace NServiceBus | |||
{ | |||
using System; | |||
using System.Net.Mail; | |||
using Config; | |||
using Notifications; | |||
|
|||
public static class BusExtensions | |||
{ | |||
public static void SendEmail(this IBus bus,MailMessage message) | |||
{ | |||
if (ConfigureNotifications.NotificationsDisabled) | |||
throw new InvalidOperationException("Send email is not supported if notifications is disabled. Please remove Configure.DisableNotifications() from your config."); | |||
|
|||
bus.Send(NotificationAddess, new SendEmail | |||
{ | |||
Message = message | |||
}); | |||
} | |||
|
|||
public static Address NotificationAddess = Address.Local.SubScope("Notifications"); | |||
} | |||
} |
13 changes: 13 additions & 0 deletions
13
src/Notifications/NServiceBus.Notifications/Config/ConfigureNotifications.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
namespace NServiceBus.Config | |||
{ | |||
public static class ConfigureNotifications | |||
{ | |||
public static Configure DisableNotifications(this Configure config) | |||
{ | |||
NotificationsDisabled = true; | |||
return config; | |||
} | |||
|
|||
public static bool NotificationsDisabled { get; set; } | |||
} | |||
} |
73 changes: 73 additions & 0 deletions
73
src/Notifications/NServiceBus.Notifications/NServiceBus.Notifications.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,73 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
<ProductVersion>8.0.30703</ProductVersion> | |||
<SchemaVersion>2.0</SchemaVersion> | |||
<ProjectGuid>{D7813FA0-5E4B-477A-BD49-791782249B38}</ProjectGuid> | |||
<OutputType>Library</OutputType> | |||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||
<RootNamespace>NServiceBus.Notifications</RootNamespace> | |||
<AssemblyName>NServiceBus.Notifications</AssemblyName> | |||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |||
<FileAlignment>512</FileAlignment> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\Debug\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\Release\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="NServiceBus"> | |||
<HintPath>..\..\..\build\output\NServiceBus.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Config"> | |||
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Config.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Installation"> | |||
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Installation.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Installation.Windows"> | |||
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Installation.Windows.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Satellites"> | |||
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Satellites.dll</HintPath> | |||
</Reference> | |||
<Reference Include="NServiceBus.Utils"> | |||
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Utils.dll</HintPath> | |||
</Reference> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Core" /> | |||
<Reference Include="Microsoft.CSharp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="Config\ConfigureNotifications.cs" /> | |||
<Compile Include="RegisterSystemMessages.cs" /> | |||
<Compile Include="BusExtensions.cs" /> | |||
<Compile Include="SendEmail.cs" /> | |||
<Compile Include="NotificationSatellite.cs" /> | |||
<Compile Include="NotifierQueueInstaller.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||
Other similar extension points exist, see Microsoft.Common.targets. | |||
<Target Name="BeforeBuild"> | |||
</Target> | |||
<Target Name="AfterBuild"> | |||
</Target> | |||
--> | |||
</Project> |
49 changes: 49 additions & 0 deletions
49
src/Notifications/NServiceBus.Notifications/NotificationSatellite.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
namespace NServiceBus.Notifications | |||
{ | |||
using System.IO; | |||
using System.Linq; | |||
using System.Net.Mail; | |||
using Config; | |||
using NServiceBus; | |||
using Satellites; | |||
using Serialization; | |||
|
|||
public class NotificationSatellite : ISatellite | |||
{ | |||
public IMessageSerializer MessageSerializer { get; set; } | |||
|
|||
public void Handle(TransportMessage message) | |||
{ | |||
SendEmail sendEmail; | |||
|
|||
using (var stream = new MemoryStream(message.Body)) | |||
sendEmail = (SendEmail)MessageSerializer.Deserialize(stream).First(); | |||
|
|||
using (var c = new SmtpClient()) | |||
c.Send(sendEmail.Message); | |||
} | |||
|
|||
public void Start() | |||
{ | |||
//no-op | |||
} | |||
|
|||
public void Stop() | |||
{ | |||
//no-op | |||
} | |||
|
|||
public Address InputAddress | |||
{ | |||
get | |||
{ | |||
return BusExtensions.NotificationAddess; | |||
} | |||
} | |||
|
|||
public bool Disabled | |||
{ | |||
get { return ConfigureNotifications.NotificationsDisabled; } | |||
} | |||
} | |||
} |
18 changes: 18 additions & 0 deletions
18
src/Notifications/NServiceBus.Notifications/NotifierQueueInstaller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
namespace NServiceBus.Notifications | |||
{ | |||
using System.Security.Principal; | |||
using Config; | |||
using Installation; | |||
using Installation.Environments; | |||
|
|||
public class NotifierQueueInstaller:INeedToInstallSomething<Windows> | |||
{ | |||
public void Install(WindowsIdentity identity) | |||
{ | |||
if (ConfigureNotifications.NotificationsDisabled) | |||
return; | |||
|
|||
Utils.MsmqUtilities.CreateQueueIfNecessary(BusExtensions.NotificationAddess,identity.Name); | |||
} | |||
} | |||
} |
Oops, something went wrong.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in the NServiceBus namespace? Can the SendEmail extension be moved to another namespace, like NServiceBus.Notifications?
And, instead of bloating the IBus interface, how about an extra property on the bus, like Bus.Notifications.SendEmail(). This is how RavenDB solves it with it's "Advanced" section of the client.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question about the SMTP mail sending addon:
Delivering the mail to your own mailserver should work in most cases, but does not tell anything about success or failure to deliver the mail to its destination.
Would you consider an option to look up the destination mailserver via DNS (MX records) and deliver directly to any of the mailservers known there? This would - of course - mean more work on the delivery process, since you cannot use the .NET framework built in SMTP classes, but instead have to follow the SMTP protocol and deliver yourself.
But it gives you much more information about if the mail could be delivered or not. E.g. "recipient not known" or "mailbox full" are errors which are sent back by the destination mailserver and you could react on this messages.
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? Will this be some kind of SendLocal containing a serialized version of the passed MailMessage? If so, does it get the same (2nd leve) retry mechanism as all other messages?
0bb5516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramonsmits best to read through this issue #1052