diff options
author | vman <public@vaughnnugent.com> | 2022-11-18 15:55:22 -0500 |
---|---|---|
committer | vman <public@vaughnnugent.com> | 2022-11-18 15:55:22 -0500 |
commit | c9e17b57a5ecdeea81674de5a033a201e7802526 (patch) | |
tree | 15c331af950441351507bb716e07dbe45452cd13 /Emails.Transactional.Client/EmailTransactionRequest.cs | |
parent | 038d86a0381b39af94b66c9bdd3da1e31cd2d8f2 (diff) |
Initial commit
Diffstat (limited to 'Emails.Transactional.Client/EmailTransactionRequest.cs')
-rw-r--r-- | Emails.Transactional.Client/EmailTransactionRequest.cs | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/Emails.Transactional.Client/EmailTransactionRequest.cs b/Emails.Transactional.Client/EmailTransactionRequest.cs new file mode 100644 index 0000000..1f1a4e2 --- /dev/null +++ b/Emails.Transactional.Client/EmailTransactionRequest.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Emails.Transactional.Client +{ + /// <summary> + /// A transactional email request to send an email + /// template. + /// </summary> + public class EmailTransactionRequest + { + /// <summary> + /// The transactional send endpoint address + /// </summary> + [JsonIgnore] + public Uri Endpoint { get; init; } + /// <summary> + /// A dictionary of email addresses/names of + /// users to send this email to + /// </summary> + [JsonPropertyName("to")] + public Dictionary<string, string> ToAddresses { get; set; } + /// <summary> + /// A dictionary of email addresses/names of + /// users to carbon copy this email to + /// </summary> + [JsonPropertyName("cc")] + public Dictionary<string, string> CcAddresses { get; set; } + /// <summary> + /// A dictionary of email addresses/names of + /// users to blind carbon copy this email to + /// </summary> + [JsonPropertyName("bcc")] + public Dictionary<string, string> BccAddresses { get; set; } + /// <summary> + /// A dictionary of variables to substitute into the liquid + /// email template + /// </summary> + [JsonPropertyName("variables")] + public Dictionary<string, string> Variables { get; set; } + + /// <summary> + /// The subject of the email to send + /// </summary> + [JsonPropertyName("subject")] + public string Subject { get; set; } + + /// <summary> + /// The unique id of the email template to send + /// </summary> + [JsonPropertyName("template_id")] + public string TemplateId { get; set; } + /// <summary> + /// The system from email name. NOTE: This is a protected value + /// </summary> + [JsonPropertyName("from_name")] + public string FromName { get; set; } + /// <summary> + /// The system from email address. NOTE: This is a protected value + /// </summary> + [JsonPropertyName("from_address")] + public string FromAddress { get; set; } + + /// <summary> + /// Creates a new email transaction with the specified email template to send + /// </summary> + /// <param name="templateId">The id of the template to send</param> + /// <exception cref="ArgumentNullException"></exception> + public EmailTransactionRequest(string templateId) + { + this.TemplateId = templateId ?? throw new ArgumentNullException(nameof(templateId)); + } + /// <summary> + /// Creates a new email transaction with the specified email template + /// and a single recipient + /// </summary> + /// <param name="templateId">The id of the template to send</param> + /// <param name="toAddress">A singular recipient name</param> + /// <param name="toName">A singlular recipient email address</param> + /// <exception cref="ArgumentNullException"></exception> + public EmailTransactionRequest(string templateId, string toName, string toAddress) + { + this.TemplateId = templateId ?? throw new ArgumentNullException(nameof(templateId)); + AddToAddress(toName, toAddress); + } + /// <summary> + /// Adds a recipient to the To email address dictionary + /// </summary> + /// <param name="toName">The name of the user to send the email to</param> + /// <param name="toAddress">The unique email address of the user to add to the recipient collection</param> + public void AddToAddress(string toName, string toAddress) + { + ToAddresses ??= new(1); + ToAddresses.Add(toAddress, toName); + } + /// <summary> + /// Adds a recipient to the To email address dictionary + /// </summary> + /// <param name="toAddress">The unique email address of the user to add to the recipient collection</param> + public void AddToAddress(string toAddress) + { + string name = toAddress.Split('@')[0]; + AddToAddress(name, toAddress); + } + /// <summary> + /// Adds a carbon copy recipient to the current cc dictionary + /// </summary> + /// <param name="ccName">The name of the recipient</param> + /// <param name="ccAddress">The unique email address of the bcc recipient</param> + public void AddCcAddress(string ccName, string ccAddress) + { + CcAddresses ??= new(1); + CcAddresses.Add(ccAddress, ccName); + } + /// <summary> + /// Adds a blind carbon copy recipient to the current bcc dictionary + /// </summary> + /// <param name="bccName">The name of the recipient</param> + /// <param name="bccAddress">The unique email address of the bcc recipient</param> + public void AddBccAddress(string bccName, string bccAddress) + { + BccAddresses ??= new(1); + BccAddresses.Add(bccAddress, bccName); + } + /// <summary> + /// Adds a liquid template variable to be subsituted by the template + /// renderer. + /// </summary> + /// <param name="varName">The unique name of the variable to add to the collection</param> + /// <param name="varValue">The value if the variable that will be substituted into the template</param> + public void AddVariable(string varName, string varValue) + { + Variables ??= new(1); + Variables.Add(varName, varValue); + } + } +} |