SmtpSender disposes itself after first send
See original GitHub issueI’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:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
#89 now spins up and disposes the SmtpClient using the given function. Not ideal, but not broken.