Skip to content

Add support for mailgun variables #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/FluentEmail.Core/Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ public IFluentEmail Tag(string tag)
return this;
}

/// <summary>
/// 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"/>
/// </summary>
/// <param name="key">Variable name</param>
/// /// <param name="value">Variable value</param>
/// <returns>Instance of the Email class</returns>
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);
Expand Down
8 changes: 8 additions & 0 deletions src/FluentEmail.Core/IFluentEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ public interface IFluentEmail: IHideObjectMembers
/// <returns>Instance of the Email class</returns>
IFluentEmail Tag(string tag);

/// <summary>
/// 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"/>
/// </summary>
/// <param name="key">Variable name</param>
/// /// <param name="value">Variable value</param>
/// <returns>Instance of the Email class</returns>
IFluentEmail Variable(string key, string value);

/// <summary>
/// Adds header to the Email.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/FluentEmail.Core/Models/EmailData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class EmailData
public string Body { get; set; }
public string PlaintextAlternativeBody { get; set; }
public Priority Priority { get; set; }
public IList<string> Tags { get; set; }
public List<string> Tags { get; set; }
public Dictionary<string, string> Variables { get; set; }

public bool IsHtml { get; set; }
public IDictionary<string, string> Headers { get; set; }
Expand All @@ -27,6 +28,7 @@ public EmailData()
ReplyToAddresses = new List<Address>();
Attachments = new List<Attachment>();
Tags = new List<string>();
Variables = new Dictionary<string, string>();
Headers = new Dictionary<string, string>();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Senders/FluentEmail.Mailgun/MailgunSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
parameters.Add(new KeyValuePair<string, string>("o:tag", x));
});

foreach (var item in email.Data.Variables)
{
parameters.Add(new KeyValuePair<string, string>($"v:{item.Key}", item.Value));
}

foreach (var emailHeader in email.Data.Headers)
{
var key = emailHeader.Key;
Expand Down