FluentEmail v3.0.0/ Multiple Cc and Bcc Recipient Issue
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.
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);
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.
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();
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?
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.
Ok, hope it will be merged soon. Is it possible to look at the implementation code?