question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending Multiple Emails - Previous recipients remains in the following emails

See original GitHub issue

Hi,

I am sending multiple emails with MailGun in the foreach loop and every next email is adding previous email address as recipient 😦

I am using DI for _email.


       await _email.To(emailAlert.Subscriber.Email)
                .Subject("My Subject")
                .Body(GetAlertBody(emailAlert), true)
                .SendAsync();

I can see in the MailGun log this, headers has 2 emails (not correct) while the recipient only one which is correct.

"message": {
        "headers": {
            "to": "email1@company.co.uk, email2@gmail.com",
            "subject": "My Subject"
        },
        "attachments": [],
        "size": 1175
    },
    "recipient": "email2@gmail.com",

Also in the Fiddler Raw I can see this, there shouldn’t be email1@company.co.uk:

Host: api.mailgun.net

--1cf329c2-d30a-41d4-a1ec-8bce3a24fd60
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=from

Uptime Monitor <DoNotReply@mg.mydomain.com>
--1cf329c2-d30a-41d4-a1ec-8bce3a24fd60
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=to

 <email1@company.co.uk>
--1cf329c2-d30a-41d4-a1ec-8bce3a24fd60
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=to

 <email2@gmail.com>
--1cf329c2-d30a-41d4-a1ec-8bce3a24fd60
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=subject

My Subject
--1cf329c2-d30a-41d4-a1ec-8bce3a24fd60
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=html

Am I doing something incorrectly and SendAsync() just builds up somehow and doesn’t clear the recipient in the header?

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
lukencodecommented, Jul 29, 2020

I actually think we should throw an exception if you try send the same email instance twice.

On Wed, 29 Jul 2020, 7:15 pm Luke Lowrey, lukenlowrey@gmail.com wrote:

Hi mattias

Yes the factory will clear the the email data.

Thanks Luke

On Wed, 29 Jul 2020, 5:34 pm Mathias Raacke, notifications@github.com wrote:

I ran into the same issue, which embarassingly caused users to receive e-mails with passwords from other users 😦

I sill don’t really understand why that is the case and where that’s mentioned in the docs. I don’t mean this as criticism, just as feedback on the usability / discoverability of the api and docs 😃

So if I understand correctly, if I change

IFluentEmail email; // injected by constructor injection

var message = _email .To(email) // …

to

IFluentEmailFactory email; // injected by constructor injection

var message = _email .Create() .To(email) // …

it should work as expected (previous recipients won’t receive additional emails)?

Regards, Mathias

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lukencode/FluentEmail/issues/117#issuecomment-665489317, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB2OWRZETHIYWE4COF42YTR57GGRANCNFSM4FQ5ZIXA .

0reactions
idbatescommented, Jun 15, 2022

This issue has just hit on on a production site with duplicate emails sent. Looking at the implementation for the To method I would have thought it safer to first clear the ToAddresses collection in the Data property - it might prevent chaining multiple calls to the To method but its hard to see why someone would do that and not simply pass a semicolon list or list of Address.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Outlook is sending multiple copies of an email
I'm having a problem with Outlook sending multiple copies of some emails - usually those with attachments.
Read more >
How to copy all the email recipients from one email I have ...
Right click the drop down icon at the end of the email address in the sent email, Left click and highlight all email...
Read more >
Your message did not reach some or all of the intended ...
Your message did not reach some or all of the intended recipients. I have three email addresses; two of which are Outlook. Since...
Read more >
Mail merge
When a recipient replies, they'll be excluded from the remaining messages in the mail merge so you can respond to them personally. Follow-up...
Read more >
E-mailing a large amount of recipients
If you have a large list of recipients you need to send an email you, you should never try sending one large email...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found