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.

SmtpSender disposes itself after first send

See original GitHub issue

I’m using Email.DefaultSender to set up SmtpSender as the sender, but upon the first send the SmtpClient object in SmtpSender is disposed, preventing any further sends until I set Email.DefaultSender to a new SmtpSender object.

That behavior is definitely not intentional I’m guessing? The root cause appears to be that SmtpSender is calling its own Dispose method after it sends an email (!).

Code to reproduce:

Email.DefaultSender = new SmtpSender();

Email
        .From("john@email.com")
        .To("bob@email.com", "bob")
        .Subject("hows it going bob")
        .Body("yo dawg, sup?")
	.Send();

Email
        .From("john@email.com")
        .To("bob@email.com", "bob")
        .Subject("hows it going bob")
        .Body("yo dawg, sup?")
	.Send();
// throws ObjectDisposedException

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kakonecommented, Apr 25, 2018

I agree that we should be able to pass our own SmtpClient and it should not be disposed by the Send method. So, I created https://github.com/lukencode/FluentEmail/pull/98/ to fix this.

0reactions
bjcullcommented, Apr 25, 2018

#89 now spins up and disposes the SmtpClient using the given function. Not ideal, but not broken.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# how to correctly dispose of an SmtpClient?
E.g. First Send() succeeds, 2nd Send() fails, 3rd Send() succeeds. Initially I thought I wasn't disposing properly. So I resorted to using() ...
Read more >
SmtpClient.Dispose Method (System.Net.Mail)
The Dispose methods iterates through all established connections and send a QUIT message to each SMTP server, followed by gracefully ending the TCP...
Read more >
SMTP Connection Policies
The rules are processed in order from left-to-right. The first rule to specify a disposition for the message determines whether the message is...
Read more >
RFC 5321: Simple Mail Transfer Protocol
The first step in the procedure is the MAIL command. MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF> This command tells the SMTP-receiver that a...
Read more >
RFC 2821 - Simple Mail Transfer Protocol (SMTP)
The first step in the procedure is the MAIL command. MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF> This command tells the SMTP-receiver that a...
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