lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.

Home Page:https://lukelowrey.com/dotnet-email-guide-2021/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FluentEmail v3.0.0/ Multiple Cc and Bcc Recipient Issue

MTKor opened this issue · comments

commented

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
"tom.tom@acme.com; mickey.moustache@acme.com; don.don@somekiosk.com" OR
"tom.tom@acme.com, mickey.moustache@acme.com, don.don@somekiosk.com".

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);
commented

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 = "test1@test.com;test2@test.com;test3@test.com";
var listOfAddress = emailString.Split(";").Select(ea => new Address { EmailAddress = ea }).ToList();
commented

Thanks a lot for your assistance. I got it working now. It is strange, though, that you can just pass a string like
"tom.tom@acme.com; mickey.moustache@acme.com; don.don@somekiosk.com" 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 #180

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

commented

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