-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Custom Mailer Approach And Inline Mailables (#405)
* new custom mailer and inline mailables * publish new version
- Loading branch information
Showing
16 changed files
with
1,002 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Coravel.Mailer.Mail; | ||
|
||
public class InlineMailable : Mailable<object> | ||
{ public override void Build() | ||
{ | ||
// No-op. This is built inline by the caller. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Coravel.Mailer.Mail; | ||
|
||
public class InlineMailable<T> : Mailable<T> | ||
{ public override void Build() | ||
{ | ||
// No-op. This is built inline by the caller. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Coravel.Mailer.Mail; | ||
|
||
public interface ICanSendMail | ||
{ | ||
Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments = null, MailRecipient sender = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Coravel.Mailer.Mail.Interfaces; | ||
using Coravel.Mailer.Mail.Renderers; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Coravel.Mailer.Mail.Mailers | ||
{ | ||
public class CanSendMailWrapper<TCanSendMail> : IMailer where TCanSendMail : ICanSendMail | ||
{ | ||
private RazorRenderer _renderer; | ||
private MailRecipient _globalFrom; | ||
private IServiceScopeFactory _scopeFactory; | ||
|
||
public CanSendMailWrapper(RazorRenderer renderer, IServiceScopeFactory scopeFactory, MailRecipient globalFrom = null) | ||
{ | ||
this._renderer = renderer; | ||
this._scopeFactory = scopeFactory; | ||
this._globalFrom = globalFrom; | ||
} | ||
|
||
public Task<string> RenderAsync<T>(Mailable<T> mailable) => | ||
mailable.RenderAsync(this._renderer, this); | ||
|
||
public async Task SendAsync<T>(Mailable<T> mailable) => | ||
await mailable.SendAsync(this._renderer, this); | ||
|
||
public async Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments, MailRecipient sender = null) | ||
{ | ||
await using (var scope = this._scopeFactory.CreateAsyncScope()) | ||
{ | ||
var canSendMail = scope.ServiceProvider.GetRequiredService<TCanSendMail>(); | ||
|
||
await canSendMail.SendAsync( | ||
message, subject, to, from ?? this._globalFrom, replyTo, cc, bcc, attachments, sender: sender | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.