Skip to content

Commit a29f45a

Browse files
committed
Added support for mailgun variables
1 parent 6ea1907 commit a29f45a

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/FluentEmail.Core/Email.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,19 @@ public IFluentEmail Tag(string tag)
485485
return this;
486486
}
487487

488+
/// <summary>
489+
/// Adds variables to the Email. This is currently only supported by the Mailgun provider. <see href="https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages"/>
490+
/// </summary>
491+
/// <param name="key">Variable name</param>
492+
/// /// <param name="value">Variable value</param>
493+
/// <returns>Instance of the Email class</returns>
494+
public IFluentEmail Variable(string key, string value)
495+
{
496+
Data.Variables.Add(key, value);
497+
498+
return this;
499+
}
500+
488501
public IFluentEmail Header(string header, string body)
489502
{
490503
Data.Headers.Add(header, body);

src/FluentEmail.Core/IFluentEmail.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ public interface IFluentEmail: IHideObjectMembers
234234
/// <returns>Instance of the Email class</returns>
235235
IFluentEmail Tag(string tag);
236236

237+
/// <summary>
238+
/// Adds variables to the Email. This is currently only supported by the Mailgun provider. <see href="https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages"/>
239+
/// </summary>
240+
/// <param name="key">Variable name</param>
241+
/// /// <param name="value">Variable value</param>
242+
/// <returns>Instance of the Email class</returns>
243+
IFluentEmail Variable(string key, string value);
244+
237245
/// <summary>
238246
/// Adds header to the Email.
239247
/// </summary>

src/FluentEmail.Core/Models/EmailData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class EmailData
1515
public string PlaintextAlternativeBody { get; set; }
1616
public Priority Priority { get; set; }
1717
public List<string> Tags { get; set; }
18+
public Dictionary<string, string> Variables { get; set; }
1819

1920
public bool IsHtml { get; set; }
2021
public Dictionary<string, string> Headers { get; set; }
@@ -27,6 +28,7 @@ public EmailData()
2728
ReplyToAddresses = new List<Address>();
2829
Attachments = new List<Attachment>();
2930
Tags = new List<string>();
31+
Variables = new Dictionary<string, string>();
3032
Headers = new Dictionary<string, string>();
3133
}
3234
}

src/Senders/FluentEmail.Mailgun/MailgunSender.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
8080
parameters.Add(new KeyValuePair<string, string>("o:tag", x));
8181
});
8282

83+
foreach (var item in email.Data.Variables)
84+
{
85+
parameters.Add(new KeyValuePair<string, string>($"v:{item.Key}", item.Value));
86+
}
87+
8388
foreach (var emailHeader in email.Data.Headers)
8489
{
8590
var key = emailHeader.Key;

0 commit comments

Comments
 (0)