cofoundry icon indicating copy to clipboard operation
cofoundry copied to clipboard

Allow input BCC, CC address list for the mail service abstraction

Open khanhtranchi opened this issue 6 years ago • 3 comments

Hi @HeyJoel ,

I want to input the BCC and CC email addresses in configuration file or manually in code but the IMailService interface doesn't implement it.

Task SendAsync(string toEmail, string toDisplayName, IMailTemplate template); Task SendAsync(string toEmail, IMailTemplate template); Task SendAsync(MailAddress address, IMailTemplate template);

To work around, I need to call Send function many times according to my list CC emails addresses. I think everyone will want to use this function a lot.

Thanks.

khanhtranchi avatar Jun 06 '18 14:06 khanhtranchi

Are you looking to CC to one or two mail addresses or a larger distribution list?

The underlying IMailDispatchService service supports sending mail in batches, so we could look at surfacing this in the IMailService or alternatively/additionally we could look at exposing multiple 'To' addresses (BCC equivalent) which would be up to the underlying provider to handle in the most economic way it can.

I'm wary of adding too much functionality to the abstraction, since every provider needs to implement the same behavior, but multiple 'To' addresses seems reasonable.

For now here's an example of using the underlying IMailDispatchService and IMailMessageRenderer to batch send mail. Performance gains depend on the underlying dispatch service implementation:

public class ExampleBatchSend
{
    private readonly IMailDispatchService _mailDispatchService;
    private readonly IMailMessageRenderer _mailMessageRenderer;

    public ExampleBatchSend(
        IMailDispatchService mailDispatchService,
        IMailMessageRenderer mailMessageRenderer
        )
    {
        _mailDispatchService = mailDispatchService;
        _mailMessageRenderer = mailMessageRenderer;
    }

    public async Task SendBatch(ICollection<MailAddress> addresses, IMailTemplate template)
    {
        using (var mailSession = _mailDispatchService.CreateSession())
        {
            foreach (var address in addresses)
            {
                var message = await _mailMessageRenderer.RenderAsync(template, address);
                    mailSession.Add(message);
            }
            await mailSession.FlushAsync();
        }
    }
}

HeyJoel avatar Jun 06 '18 14:06 HeyJoel

Hello, I would like to send a mail with a different "reply-to" email. Is it possible ? Thanks

dumboster avatar May 27 '19 10:05 dumboster

@dumboster see #323

HeyJoel avatar May 27 '19 11:05 HeyJoel