FluentEmail icon indicating copy to clipboard operation
FluentEmail copied to clipboard

FluentEmail v3.0.0/ Multiple Cc and Bcc Recipient Issue

Open MTKor opened this issue 4 years ago • 7 comments

I am working on an urgent project involving FluentMail to process outgoing email messages.

The problem is that I have not been able to figure out a way to send Cc and/or Bcc messages to multiple recipients, only one.

I have also tested it with hard-coded recipients, like "[email protected]; [email protected]; [email protected]" OR "[email protected], [email protected], [email protected]".

What happens is that the Cc or Bcc message ends up being sent only to the last recipient in the list.

I would very much appreciate advise on how to send a message to multiple Cc and Bcc reciepients and, if this feature is not currently supported, I hope that this feature would be implemented soon.

MTKor avatar Oct 07 '21 16:10 MTKor

You can generate a list of Address (Address is in FluentEmail.Core.Models) and then pass it into .BCC().

Something like this.

_BCCAddresses = config.GetSection("BCCAddresses").Get<List<string>>().Select(ea => new Address { EmailAddress = ea }).ToList();

var email = _emailFactory.Create()
  .To(toAddress) 
  .BCC(_BCCAddresses)
  .Subject("Subect")
  .UsingTemplateFromFile($@"path\to\template", model, true);

McPhale avatar Oct 07 '21 19:10 McPhale

Thank you for your help. C# is still quite new language to me so excuse me for that. I made a test and added some email addresses to a list hard-coded and it seemed to work i.e. the Cc and Bcc messages were sent to each listed recipient.

I understand that your given example reads a list and returns a list, right? In my case, I get a string containing the email addresses separated by semicolon ";". Could you suggest a handy way to add all those email addresses to a list that would be passed to .CC or BCC?

Thanks in advance.

MTKor avatar Oct 09 '21 06:10 MTKor

No worries :) you can use string.split() for that. Here's an example

var emailString = "[email protected];[email protected];[email protected]";
var listOfAddress = emailString.Split(";").Select(ea => new Address { EmailAddress = ea }).ToList();

McPhale avatar Oct 11 '21 17:10 McPhale

Thanks a lot for your assistance. I got it working now. It is strange, though, that you can just pass a string like "[email protected]; [email protected]; [email protected]" to .TO() and it works, but the same does not apply to .CC() or .BCC(). I just wonder why is that?

MTKor avatar Oct 14 '21 16:10 MTKor

It's just not implemented yet; see https://github.com/lukencode/FluentEmail/pull/180

Looks like there's already a pull request active for it.

McPhale avatar Oct 14 '21 19:10 McPhale

Ok, hope it will be merged soon. Is it possible to look at the implementation code?

MTKor avatar Oct 15 '21 05:10 MTKor

2569026 (#180)

McPhale avatar Oct 15 '21 15:10 McPhale