Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build & Test

on:
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,5 @@ ModelManifest.xml

# Verify test files
*.received.txt

.env
3 changes: 3 additions & 0 deletions FluentEmail.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6DC215BD-05EF-49A6-ADBE-8AE399952EEC}"
ProjectSection(SolutionItems) = preProject
test\Directory.Build.props = test\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D5C44238-0312-43F8-9705-EACFB039A48C}"
EndProject
Expand Down
4 changes: 4 additions & 0 deletions FluentEmail.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=endfor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=logotest/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mailtrap/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/FluentEmail.Core/FluentEmail.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions src/Senders/FluentEmail.Mailtrap/MailtrapSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace FluentEmail.Mailtrap
/// </summary>
public class MailtrapSender : IMailtrapSender, IDisposable
{
private const string URL = "https://send.api.mailtrap.io/api/send";
private readonly SmtpClient _smtpClient;
private static readonly int[] ValidPorts = {25,587, 2525};
private readonly string _apiKey;
private readonly string _apiHost;

/// <summary>
/// Creates a sender that uses the given Mailtrap credentials, but does not dispose it.
Expand All @@ -31,7 +31,7 @@ public class MailtrapSender : IMailtrapSender, IDisposable
/// <param name="password">Password of your mailtrap.io SMTP inbox</param>
/// <param name="host">Host address for the Mailtrap.io SMTP inbox</param>
/// <param name="port">Port for the Mailtrap.io SMTP server. Accepted values are 25, 465 or 2525.</param>
public MailtrapSender(string userName, string password, string host = "smtp.mailtrap.io", int? port = null)
public MailtrapSender(string userName, string password, string host = "smtp.mailtrap.io", int? port = null, string apiHost = "https://send.api.mailtrap.io/api/send")
{
if (string.IsNullOrWhiteSpace(userName))
throw new ArgumentException("Mailtrap UserName needs to be supplied", nameof(userName));
Expand All @@ -42,6 +42,7 @@ public MailtrapSender(string userName, string password, string host = "smtp.mail
if (port.HasValue && !ValidPorts.Contains(port.Value))
throw new ArgumentException("Mailtrap Port needs to be either 25, 465 or 2525", nameof(port));
_apiKey = password;
_apiHost = apiHost;
_smtpClient = new SmtpClient(host, port.GetValueOrDefault(587))
{
Credentials = new NetworkCredential(userName, password),
Expand All @@ -66,12 +67,12 @@ public Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken? token
public async Task<SendResponse> SendWithTemplateAsync(IFluentEmail email, string templateName, object templateData, CancellationToken? token = null)
{
token?.ThrowIfCancellationRequested();
using (var httpClient = new HttpClient { BaseAddress = new Uri(URL) })
using (var httpClient = new HttpClient { BaseAddress = new Uri(_apiHost) })
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var jsonContent = HttpClientHelpers.GetJsonBody(BuildMailtrapParameters(email, templateName, templateData));
var response = await httpClient.Post<MailtrapResponse>(URL, jsonContent);
var response = await httpClient.Post<MailtrapResponse>(_apiHost, jsonContent);
var result = new SendResponse { MessageId = response.Data?.Id };
if (!response.Success)
{
Expand Down
3 changes: 1 addition & 2 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageReference Include="xunit.v3" Version="3.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
29 changes: 17 additions & 12 deletions test/FluentEmail.Bootstrap.Tests/BootstrapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Threading.Tasks;
using FluentEmail.Core;
using FluentEmail.Core.Interfaces;
using FluentEmail.Liquid;
using Fluid;
using Microsoft.Extensions.FileProviders;
Expand All @@ -25,11 +26,9 @@ public BootstrapTests()
{
_settings.ScrubLinesContaining("Compiled with Bootstrap Email DotNet");
_settings.DisableDiff();
// default to have no file provider, only required when layout files are in use
SetupRenderer();
}

private static void SetupRenderer(
private static ITemplateRenderer SetupRenderer(
IFileProvider fileProvider = null,
Action<TemplateContext, object> configureTemplateContext = null)
{
Expand All @@ -38,7 +37,7 @@ private static void SetupRenderer(
FileProvider = fileProvider,
ConfigureTemplateContext = configureTemplateContext,
};
Email.DefaultRenderer = new LiquidRenderer(Options.Create(options));
return new LiquidRenderer(Options.Create(options));
}

[Fact]
Expand All @@ -51,11 +50,13 @@ public Task CompileBootstrap_Compiles()
</body>
</html>
""";
var email = Email
.From(FromEmail)
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingTemplate(template, new ViewModel { Name = "LUKE", Numbers = new[] { "1", "2", "3" } })
.UsingTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] })
.CompileBootstrap();

return Verifier.Verify(email.Data.Body, _settings);
Expand All @@ -71,8 +72,10 @@ public Task UsingBootstrapBody_Compiles()
</body>
</html>
""";
var email = Email
.From(FromEmail)
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingBootstrapBody(body);
Expand All @@ -91,11 +94,13 @@ public Task UsingBootstrapTemplate_Compiles()
</body>
</html>
""";
var email = Email
.From(FromEmail)
var email = new Email(FromEmail)
{
Renderer = SetupRenderer()
}
.To(ToEmail)
.Subject(Subject)
.UsingBootstrapTemplate(template, new ViewModel { Name = "LUKE", Numbers = new[] { "1", "2", "3" } });
.UsingBootstrapTemplate(template, new ViewModel { Name = "LUKE", Numbers = ["1", "2", "3"] });

return Verifier.Verify(email.Data.Body, _settings);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,10 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.21" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Verify.XunitV3" Version="31.0.2" />
<PackageReference Include="Verify.XunitV3" Version="31.0.3" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions test/FluentEmail.Core.Tests/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FE_TEST_TO_EMAIL=
FE_TEST_FROM_EMAIL=

# MailTrap Tests Credentials
FE_TEST_MAILTRAP_TO_EMAIL=
FE_TEST_MAILTRAP_FROM_EMAIL=
FE_TEST_MAILTRAP_HOST=
FE_TEST_MAILTRAP_USER=
FE_TEST_MAILTRAP_PWD=
FE_TEST_MAILTRAP_PORT=587
FE_TEST_MAILTRAP_API_HOST=
FE_TEST_MAILTRAP_API_KEY=
FE_TEST_MAILTRAP_TEMPLATE=

# MailGun Tests Credentials
FE_TEST_MAILGUN_TO_EMAIL=
FE_TEST_MAILGUN_FROM_EMAIL=
FE_TEST_MAILGUN_DOMAIN=
FE_TEST_MAILGUN_API_KEY=

# Azure Email Service Credentials
FE_TEST_AZURE_TO_EMAIL=
FE_TEST_AZURE_FROM_EMAIL=
FE_TEST_AZURE_API_HOST=

# Postmark Credentials
FE_TEST_POSTMARK_API_KEY=
FE_TEST_POSTMARK_FROM_EMAIL=

# SendGrid Credentials
FE_TEST_SENDGRID_API_KEY=
FE_TEST_SENDGRID_TEMPLATE=

# Graph Credentials
FE_TEST_GRAPH_TO_EMAIL=
FE_TEST_GRAPH_FROM_EMAIL=
FE_TEST_GRAPH_TENANT_ID=
FE_TEST_GRAPH_APP_ID=
FE_TEST_GRAPH_CLIENT_SECRET=
Loading
Loading