-
Notifications
You must be signed in to change notification settings - Fork 3
gl-dotnet-email changes for Cc, Bcc, ReplyTo, and attachments #33
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
base: develop
Are you sure you want to change the base?
Changes from all commits
2ae944b
6a9a2fc
28b5117
52d1bcb
b241f9a
35d7331
36618ae
08fb23e
d9198ab
2a1cf73
9635f2a
19bbf69
3d2e989
b5dbc89
2e4b9e1
90d4f8d
2493e33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,19 +22,33 @@ public IActionResult Index() | |
|
||
public async Task<IActionResult> SendEmail() | ||
{ | ||
var user = new User | ||
|
||
EmailAddress toAddress1 = new EmailAddress() { Email = "[email protected]", DisplayName = "Bob" }; | ||
EmailAddress toAddress2 = new EmailAddress() { Email = "[email protected]", DisplayName = "Sam" }; | ||
|
||
// example of how to add a simple attachment. Add images, streams, etc as byte arrays, for example: | ||
|
||
MimeKit.AttachmentCollection attachments = new MimeKit.AttachmentCollection | ||
{ | ||
Email = "[email protected]", | ||
DisplayName = "John Doe" | ||
{ "sample_attachment.txt", System.Text.Encoding.UTF8.GetBytes("This is the content of the file attachment.") } | ||
}; | ||
|
||
|
||
|
||
await this.emailSender.SendEmailAsync(new EmailAddress() { Email="[email protected]", DisplayName="Me" }, "A simple message","This is a test message", attachments, toAddress1); | ||
|
||
|
||
// Here is a second send example. No attachments, but using templates. Specifies to send a Cc to ccRecipient, using a decorator: | ||
|
||
IEmailAddress ccRecipient = new EmailAddress() { Email = "[email protected]", DisplayName = "Joe Smith" }; | ||
|
||
var context = new | ||
{ | ||
ApplicationName = "Email Sender Sample", | ||
User = user | ||
User = toAddress1 | ||
}; | ||
await this.emailSender.SendTemplatedEmailAsync("Invitation", context, toAddress2, ccRecipient.ToCc() ); | ||
|
||
await this.emailSender.SendTemplatedEmailAsync("Invitation", context, user); | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace GeekLearning.Email | ||
namespace GeekLearning.Email | ||
{ | ||
public interface IEmailAddress | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
namespace GeekLearning.Email | ||
namespace GeekLearning.Email | ||
{ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
using MimeKit; | ||
|
||
public interface IEmailProvider | ||
{ | ||
Task SendEmailAsync(IEmailAddress from, IEnumerable<IEmailAddress> recipients, string subject, string bodyText, string bodyHtml); | ||
Task SendEmailAsync( | ||
IEmailAddress from, | ||
IEnumerable<IEmailAddress> recipients, | ||
string subject, | ||
string bodyText, | ||
string bodyHtml | ||
AttachmentCollection attachments=null); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,20 @@ | |
|
||
public interface IEmailSender | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there should be additional overloads using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a thought. But there needs to be a solid way to link an AddressTarget to an email address. And how does it look if we have multiple email addresses in the call? |
||
{ | ||
Task SendEmailAsync(string subject, string message, AttachmentCollection attachments, params IEmailAddress[] to); | ||
|
||
Task SendEmailAsync(string subject, string message, params IEmailAddress[] to); | ||
|
||
Task SendEmailAsync(IEmailAddress from, string subject, string message, params IEmailAddress[] to); | ||
|
||
Task SendEmailAsync(IEmailAddress from, string subject, string message, AttachmentCollection attachments, params IEmailAddress[] to); | ||
|
||
Task SendTemplatedEmailAsync<T>(string templateKey, T context, AttachmentCollection attachments, params IEmailAddress[] to); | ||
|
||
Task SendTemplatedEmailAsync<T>(string templateKey, T context, params IEmailAddress[] to); | ||
|
||
Task SendTemplatedEmailAsync<T>(IEmailAddress from, string templateKey, T context, params IEmailAddress[] to); | ||
|
||
Task SendTemplatedEmailAsync<T>(IEmailAddress from, string templateKey, T context, AttachmentCollection attachments, params IEmailAddress[] to); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,17 +55,12 @@ public async Task SendNotification1(string storeName) | |
new SendGrid.SendGridEmailProviderType(), | ||
}; | ||
|
||
var emailSender = new Internal.EmailSender( | ||
providerTypes, | ||
options, | ||
this.storeFixture.Services.GetRequiredService<IStorageFactory>(), | ||
this.storeFixture.Services.GetRequiredService<ITemplateLoaderFactory>()); | ||
IEmailAddress address = new Internal.EmailAddress() { | ||
DisplayName = "test user", | ||
Email = "[email protected]" | ||
}; | ||
|
||
await emailSender.SendTemplatedEmailAsync("Notification1", new { }, new Internal.EmailAddress | ||
{ | ||
DisplayName = "test user", | ||
Email = "[email protected]" | ||
}); | ||
await emailSender.SendTemplatedEmailAsync("Notification1", new { }, address); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IEmailProvider
should probably useAddressTarget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to be able to define a complete email transaction in one call. You might want to send to two (or more) different addresses, Cc: another, and Bcc: yet another, and also have a ReplyTo: for the message that is different that the From: address. (some hosting services required the From address to match the authentication user name, which might not be the same as the 'sender' of the immediate message). Using an attribute parameter for the email address implies a single target transaction. Slower if the app wants to send to several targets.