Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Upgraded project to .NET 4

- BREAKING (but awesome) CHANGe - replaced templating with RazorEngine templates http://razorengine.codeplex.com.
- Added nuget package reference to RazorEngine
- Changed ReplyTo to use ReplyToList
- Updated and added some tests
  • Loading branch information...
commit dc5562c35ad71f8567ad6ce0eba35b655a9b9e83 1 parent 065ece7
@lukencode lukencode authored
View
2  FluentEmail.sln
@@ -5,8 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentEmail", "FluentEmail\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentEmail.Tests", "FluentEmailTests\FluentEmail.Tests.csproj", "{595F5D5C-F2F2-4E23-90D6-5D75CB73BF4F}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D8A38E5-15B0-4C2B-BD49-ED629E5DDC42}"
-EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = FluentEmail.vsmdi
View
191 FluentEmail/FluentEmail.cs
@@ -1,191 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Net.Mail;
-
-namespace FluentEmail
-{
- public class Email : IHideObjectMembers
- {
- private SmtpClient _client;
- private bool _useSsl;
-
- public MailMessage Message { get; set; }
-
- private Email()
- {
- Message = new MailMessage();
- _client = new SmtpClient();
- }
-
- /// <summary>
- /// Creates a new Email instance and sets the from
- /// property
- /// </summary>
- /// <param name="emailAddress">Email address to send from</param>
- /// <param name="name">Name to send from</param>
- /// <returns>Instance of the Email class</returns>
- public static Email From(string emailAddress, string name = "")
- {
- var email = new Email();
- email.Message.From = new MailAddress(emailAddress, name);
- return email;
- }
-
- /// <summary>
- /// Adds a reciepient to the email
- /// </summary>
- /// <param name="emailAddress">Email address of recipeient</param>
- /// <param name="name">Name of recipient</param>
- /// <returns>Instance of the Email class</returns>
- public Email To(string emailAddress, string name = "")
- {
- Message.To.Add(new MailAddress(emailAddress, name));
- return this;
- }
-
- /// <summary>
- /// Adds all reciepients in list to email
- /// </summary>
- /// <param name="mailAddresses">List of recipients</param>
- /// <returns>Instance of the Email class</returns>
- public Email To(IList<MailAddress> mailAddresses)
- {
- foreach (var address in mailAddresses)
- {
- Message.To.Add(address);
- }
- return this;
- }
-
- /// <summary>
- /// Adds a Carbon Copy to the email
- /// </summary>
- /// <param name="emailAddress">Email address to cc</param>
- /// <param name="name">Name to cc</param>
- /// <returns>Instance of the Email class</returns>
- public Email CC(string emailAddress, string name = "")
- {
- Message.CC.Add(new MailAddress(emailAddress, name));
- return this;
- }
-
- /// <summary>
- /// Adds a blind carbon copy to the email
- /// </summary>
- /// <param name="emailAddress">Email address of bcc</param>
- /// <param name="name">Name of bcc</param>
- /// <returns>Instance of the Email class</returns>
- public Email BCC(string emailAddress, string name = "")
- {
- Message.Bcc.Add(new MailAddress(emailAddress, name));
- return this;
- }
-
- /// <summary>
- /// Sets the subject of the email
- /// </summary>
- /// <param name="subject">email subject</param>
- /// <returns>Instance of the Email class</returns>
- public Email Subject(string subject)
- {
- Message.Subject = subject;
- return this;
- }
-
- /// <summary>
- /// Adds a Body to the Email
- /// </summary>
- /// <param name="body">The content of the body</param>
- /// <param name="isHtml">True if Body is HTML, false for plain text (Optional)</param>
- /// <returns></returns>
- public Email Body(string body, bool isHtml = true)
- {
- Message.Body = body;
- Message.IsBodyHtml = isHtml;
- return this;
- }
-
- /// <summary>
- /// Adds an Attachment to the Email
- /// </summary>
- /// <param name="attachment">The Attachment to add</param>
- /// <returns>Instance of the Email class</returns>
- public Email Attach(Attachment attachment)
- {
- if (!Message.Attachments.Contains(attachment))
- Message.Attachments.Add(attachment);
- return this;
- }
-
- /// <summary>
- /// Adds Multiple Attachments to the Email
- /// </summary>
- /// <param name="attachments">The List of Attachments to add</param>
- /// <returns>Instance of the Email class</returns>
- public Email Attach(IList<Attachment> attachments)
- {
- foreach (var attachment in attachments)
- {
- if (!Message.Attachments.Contains(attachment))
- Message.Attachments.Add(attachment);
- }
- return this;
- }
-
- /// <summary>
- /// Over rides the default client from .config file
- /// </summary>
- /// <param name="client">Smtp client to send from</param>
- /// <returns>Instance of the Email class</returns>
- public Email UsingClient(SmtpClient client)
- {
- _client = client;
- return this;
- }
-
- public Email UseSSL()
- {
- _useSsl = true;
- return this;
- }
-
- /// <summary>
- /// Sends email synchronously
- /// </summary>
- /// <returns>Instance of the Email class</returns>
- public Email Send()
- {
- _client.EnableSsl = _useSsl;
- _client.Send(Message);
- return this;
- }
-
- /// <summary>
- /// Sends message asynchronously with a callback
- /// handler
- /// </summary>
- /// <param name="callback">Method to call on complete</param>
- /// <param name="token">User token to pass to callback</param>
- /// <returns>Instance of the Email class</returns>
- public Email SendAsync(SendCompletedEventHandler callback, object token = null)
- {
- _client.EnableSsl = _useSsl;
- _client.SendCompleted += callback;
- _client.SendAsync(Message, token);
-
- return this;
- }
-
- /// <summary>
- /// Cancels async message sending
- /// </summary>
- /// <returns>Instance of the Email class</returns>
- public Email Cancel()
- {
- _client.SendAsyncCancel();
- return this;
- }
- }
-}
View
20 FluentEmail/FluentEmail.csproj
@@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FluentEmail</RootNamespace>
<AssemblyName>FluentEmail</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject />
<TargetFrameworkProfile />
@@ -33,19 +33,27 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="RazorEngine">
+ <HintPath>..\packages\RazorEngine.2.1\lib\.NetFramework 4.0\RazorEngine.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
- <Reference Include="System.Xml" />
+ <Reference Include="System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <Private>True</Private>
+ <HintPath>..\packages\RazorEngine.2.1\lib\.NetFramework 4.0\System.Web.Razor.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="FluentEmail.cs" />
+ <Compile Include="Email.cs" />
<Compile Include="IHideObjectMembers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="FluentEmail.nuspec" />
+ <None Include="packages.config" />
+ </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.
View
13 FluentEmail/FluentEmail.nuspec
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <metadata>
+ <id>$id$</id>
+ <version>$version$</version>
+ <authors>$author$</authors>
+ <owners>$author$</owners>
+ <projectUrl>https://github.com/lukencode/FluentEmail</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>$description$</description>
+ <tags>email fluent</tags>
+ </metadata>
+</package>
View
3  FluentEmail/IHideObjectMembers.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.ComponentModel;
namespace FluentEmail
View
4 FluentEmail/Properties/AssemblyInfo.cs
@@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FluentEmail")]
-[assembly: AssemblyDescription("")]
+[assembly: AssemblyDescription("A Fluent Wrapper for System.Net.Mail")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("Luke Lowrey")]
[assembly: AssemblyProduct("FluentEmail")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
View
4 FluentEmail/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="RazorEngine" version="2.1" />
+</packages>
View
13 FluentEmailTests/FluentEmail.Tests.csproj
@@ -40,10 +40,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="AddressTests.cs" />
<Compile Include="AsyncTests.cs" />
<Compile Include="FluentEmailTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SendTests.cs" />
+ <Compile Include="TemplateEmailTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FluentEmail\FluentEmail.csproj">
@@ -51,6 +53,17 @@
<Name>FluentEmail</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Resource Include="test.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Resource>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Emails\" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\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.
View
12 FluentEmailTests/FluentEmailTests.cs
@@ -81,6 +81,7 @@ public void Can_Add_Multiple_Recipients_From_List()
Assert.AreEqual(2, email.Message.To.Count);
}
+ [TestMethod]
public void Is_Valid_With_Properties_Set()
{
var email = Email
@@ -94,5 +95,16 @@ public void Is_Valid_With_Properties_Set()
Assert.AreEqual(fromEmail, email.Message.From.Address);
Assert.AreEqual(toEmail, email.Message.To[0].Address);
}
+
+ [TestMethod]
+ public void ReplyTo_Address_Is_Set()
+ {
+ var replyEmail = "reply@email.com";
+
+ var email = Email.From(fromEmail)
+ .ReplyTo(replyEmail);
+
+ Assert.AreEqual(replyEmail, email.Message.ReplyToList.First().Address);
+ }
}
}
View
16 FluentEmailTests/SendTests.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Text;
-using System.Collections.Generic;
-using System.Linq;
+using FluentEmail;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FluentEmailTests
@@ -12,6 +9,17 @@ public class SendTests
[TestMethod]
public void TestMethod1()
{
+ string toEmail = "bob@test.com";
+ string fromEmail = "johno@test.com";
+ string subject = "sup dawg";
+ string body = "what be the hipitity hap?";
+
+ var email = Email
+ .From(fromEmail)
+ .To(toEmail)
+ .Subject(subject)
+ .Body(body)
+ .Send();
}
}
}
View
16 README.markdown
@@ -7,6 +7,19 @@ Example usage from:
.To("bob@email.com", "bob")
.Subject("hows it going bob")
.Body("yo dawg, sup?");
+
+
+Templates usage:
+ var email = Email
+ .From("john@email.com")
+ .To("bob@email.com", "bob")
+ .Subject("hows it going bob")
+ .UsingTemplate(@"C:\Emailer\TransactionTemplate.htm")
+ .Replace("<%CurrentDate%>", DateTime.Now.ToShortDateString())
+ .Replace("<%FullName%>", fullName)
+ .Replace("<%SaleDate%>", saleDate)
+
+Sending:
//send normally
email.Send();
@@ -14,4 +27,5 @@ Example usage from:
//send asynchronously
email.SendAsync(MailDeliveredCallback);
-http://lukencode.com/2010/04/11/fluent-email-in-net
+
+<a href="http://lukencode.com/2010/04/11/fluent-email-in-net">http://lukencode.com/2010/04/11/fluent-email-in-net</a>
View
BIN  packages/RazorEngine.2.1/RazorEngine.2.1.nupkg
Binary file not shown
View
BIN  packages/RazorEngine.2.1/lib/.NetFramework 4.0/RazorEngine.dll
Binary file not shown
View
BIN  packages/RazorEngine.2.1/lib/.NetFramework 4.0/System.Web.Razor.dll
Binary file not shown
View
4 packages/repositories.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..\FluentEmail\packages.config" />
+</repositories>
Please sign in to comment.
Something went wrong with that request. Please try again.