Skip to content

Commit e37a539

Browse files
DeProgrammerRon Petrusha
authored andcommitted
Note about Dispose affecting Attachments (#2902)
https://referencesource.microsoft.com/#system/net/System/Net/mail/MailMessage.cs,a22b7e48cd4bc831 Disposing of Attachments also closes the Streams they're using. The problem I had that caused me to dig into the code wasn't relevant to this change, but I saw it as a potential occasional issue. A MailMessage intuitively shouldn't take this kind of ownership of an Attachment that was given to it by an external source since the documentation suggests that Attachments can be reused. In my mind, "not intuitive" means "needs to be clearly documented."
1 parent ee4effc commit e37a539

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

xml/System.Net.Mail/MailMessage.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
9494
Use the <xref:System.Net.Mail.MailMessage.AlternateViews%2A> property to specify copies of an email message in different formats. For example, if you send a message in HTML, you might also want to provide a plain text version in case some of the recipients use email readers that cannot display HTML content. For an example that demonstrates creating a message with alternate views, see <xref:System.Net.Mail.MailMessage.AlternateViews%2A>.
9595
96-
Use the <xref:System.Net.Mail.MailMessage.Attachments%2A> property to add attachments to an email message. For an example that demonstrates creating a message with an attachment, see <xref:System.Net.Mail.MailMessage.Attachments%2A>.
96+
Use the <xref:System.Net.Mail.MailMessage.Attachments%2A> property to add attachments to an email message. For an example that demonstrates creating a message with an attachment, see <xref:System.Net.Mail.MailMessage.Attachments%2A>. Calling Dispose on the MailMessage also calls Dispose on each referenced Attachment.
9797
9898
After assembling your email message, you can send it by using the <xref:System.Net.Mail.SmtpClient.Send%2A> or <xref:System.Net.Mail.SmtpClient.SendAsync%2A> methods.
9999
@@ -1408,4 +1408,4 @@
14081408
</Docs>
14091409
</Member>
14101410
</Members>
1411-
</Type>
1411+
</Type>

0 commit comments

Comments
 (0)