-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathISingleEmailSender.cs
More file actions
132 lines (121 loc) · 4.32 KB
/
ISingleEmailSender.cs
File metadata and controls
132 lines (121 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OrderCloud.Catalyst
{
/// <summary>
/// A simple email sender. Intended for "Transactional emails", meaning notifications in response to an action taken in an appplication, like reset password or order submitted. This is as opposed to batches or marketing campaigns.
/// </summary>
public interface ISingleEmailSender
{
/// <summary>
/// Send a single email, as opposed to a batch of emails or an email campaign. Multiple recipients with personalized templates supported.
/// </summary>
Task SendSingleEmailAsync(EmailMessage message, OCIntegrationConfig overrideConfig = null);
}
/// <summary>
/// Email Address
/// </summary>
public class EmailAddress
{
public EmailAddress() { }
public EmailAddress(string email)
{
Email = email;
}
/// <summary>
/// The actual Email address. Required.
/// </summary>
public string Email { get; set; }
/// <summary>
/// Name of the address. Optional.
/// </summary>
public string Name { get; set; }
}
/// <summary>
/// Email Address
/// </summary>
public class ToEmailAddress : EmailAddress
{
public ToEmailAddress() { }
public ToEmailAddress(string email)
{
Email = email;
}
public ToEmailAddress(EmailAddress email)
{
Email = email.Email;
Name = email.Name;
}
/// <summary>
/// Dynamic data specific to this recipient used to populate the template. Overrides values in EmailMessage.GlobalTemplateData. Ignored if AllRecipientsVisibleOnSingleThread is true. Optional.
/// </summary>
public Dictionary<string, object> TemplateDataOverrides { get; set; } = new Dictionary<string, object>();
}
/// <summary>
/// All the data to send an email. Supports multiple recipients, templatization by recipient, attachments, and either one shared thread or individual messages.
/// </summary>
public class EmailMessage
{
/// <summary>
/// Subject line of the email
/// </summary>
public string Subject { get; set; }
/// <summary>
/// Contents of the email. Can be null if the TemplateID property is not null. Will override TemplateID if both are non-null. Assumed to be in HTML format, though a raw string should work.
/// </summary>
public string Content { get; set; }
/// <summary>
/// From address of the email.
/// </summary>
public EmailAddress FromAddress { get; set; }
/// <summary>
/// List of addresses to send the email to.
/// </summary>
public List<ToEmailAddress> ToAddresses { get; set; } = new List<ToEmailAddress>();
/// <summary>
/// Reference to an existing email content template in the email automation system. Can be null if the Content property is not null. Will be overriden by Content if both are non-null.
/// </summary>
public string TemplateID { get; set; }
/// <summary>
/// Dynamic data used to populate the template. Key value strings only. Optional.
/// </summary>
public Dictionary<string, object> GlobalTemplateData { get; set; } = new Dictionary<string, object>();
/// <summary>
/// List of files to attach to the email. Optional.
/// </summary>
public List<EmailAttachment> Attachments { get; set; } = new List<EmailAttachment>();
/// <summary>
/// If true, all recipients will see each other on a single thread and ToEmailAddress.TemplateDataOverrides will do nothing. If false, recipients will recieve personal emails. Defaults to false.
/// </summary>
public bool AllRecipientsVisibleOnSingleThread { get; set; } = false;
}
public class EmailAttachment
{
public EmailAttachment() { }
/// <summary>
/// Do not use with large files as all the data is put into a byte[] in memory
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public EmailAttachment(IFormFile file)
{
MIMEType = file.ContentType;
FileName = file.FileName;
ContentBase64Encoded = Convert.ToBase64String(file.ToByteArray());
}
/// <summary>
/// The data for the attached file in Base64Encoded format
/// </summary>
public string ContentBase64Encoded { get; set; }
/// <summary>
/// Multipurpose Internet Mail Extensions type. For example, "text/html", "image/png", ect.
/// </summary>
public string MIMEType { get; set; }
/// <summary>
/// The name of the file to display
/// </summary>
public string FileName { get; set; }
}
}