From 64cf341b530d78f8ec8c6ee180109cafe7d2e519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Keresztury?= Date: Mon, 25 May 2020 15:14:10 +0200 Subject: [PATCH] Added support for mailgun variables --- src/FluentEmail.Core/Email.cs | 13 +++++++++++++ src/FluentEmail.Core/IFluentEmail.cs | 8 ++++++++ src/FluentEmail.Core/Models/EmailData.cs | 4 +++- src/Senders/FluentEmail.Mailgun/MailgunSender.cs | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/FluentEmail.Core/Email.cs b/src/FluentEmail.Core/Email.cs index 57142656..0af87425 100644 --- a/src/FluentEmail.Core/Email.cs +++ b/src/FluentEmail.Core/Email.cs @@ -484,6 +484,19 @@ public IFluentEmail Tag(string tag) return this; } + /// + /// Adds variables to the Email. This is currently only supported by the Mailgun provider. + /// + /// Variable name + /// /// Variable value + /// Instance of the Email class + public IFluentEmail Variable(string key, string value) + { + Data.Variables.Add(key, value); + + return this; + } + public IFluentEmail Header(string header, string body) { Data.Headers.Add(header, body); diff --git a/src/FluentEmail.Core/IFluentEmail.cs b/src/FluentEmail.Core/IFluentEmail.cs index f22197ac..e234851c 100644 --- a/src/FluentEmail.Core/IFluentEmail.cs +++ b/src/FluentEmail.Core/IFluentEmail.cs @@ -234,6 +234,14 @@ public interface IFluentEmail: IHideObjectMembers /// Instance of the Email class IFluentEmail Tag(string tag); + /// + /// Adds variables to the Email. This is currently only supported by the Mailgun provider. + /// + /// Variable name + /// /// Variable value + /// Instance of the Email class + IFluentEmail Variable(string key, string value); + /// /// Adds header to the Email. /// diff --git a/src/FluentEmail.Core/Models/EmailData.cs b/src/FluentEmail.Core/Models/EmailData.cs index 2ba104e5..4d0626de 100644 --- a/src/FluentEmail.Core/Models/EmailData.cs +++ b/src/FluentEmail.Core/Models/EmailData.cs @@ -14,7 +14,8 @@ public class EmailData public string Body { get; set; } public string PlaintextAlternativeBody { get; set; } public Priority Priority { get; set; } - public IList Tags { get; set; } + public List Tags { get; set; } + public Dictionary Variables { get; set; } public bool IsHtml { get; set; } public IDictionary Headers { get; set; } @@ -27,6 +28,7 @@ public EmailData() ReplyToAddresses = new List
(); Attachments = new List(); Tags = new List(); + Variables = new Dictionary(); Headers = new Dictionary(); } } diff --git a/src/Senders/FluentEmail.Mailgun/MailgunSender.cs b/src/Senders/FluentEmail.Mailgun/MailgunSender.cs index c1f3f359..1b8cf369 100644 --- a/src/Senders/FluentEmail.Mailgun/MailgunSender.cs +++ b/src/Senders/FluentEmail.Mailgun/MailgunSender.cs @@ -80,6 +80,11 @@ public async Task SendAsync(IFluentEmail email, CancellationToken? parameters.Add(new KeyValuePair("o:tag", x)); }); + foreach (var item in email.Data.Variables) + { + parameters.Add(new KeyValuePair($"v:{item.Key}", item.Value)); + } + foreach (var emailHeader in email.Data.Headers) { var key = emailHeader.Key;