Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5941535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:07:27+00:00 2026-05-22T16:07:27+00:00

When I use SmtpClient’s SendAsync to send email, how do I dispose the smtpclient

  • 0

When I use SmtpClient’s SendAsync to send email, how do I dispose the smtpclient instance correctly?

Let’s say:


MailMessage mail = new System.Net.Mail.MailMessage()
{
   Body = MailBody.ToString(),
   IsBodyHtml = true,
   From = new MailAddress(FromEmail, FromEmailTitle),
   Subject = MailSubject
};
mail.To.Add(new MailAddress(i.Email, ""));
SmtpClient sc = new SmtpClient(SmtpServerAddress);
//Add SendAsyncCallback to SendCompleted
sc.SendCompleted += new SendCompletedEventHandler(SendAsyncCallback);
//using SmtpClient to make async send (Should I pass sc or mail into SendAsyncCallback?)
sc.SendAsync(mail, sc);

In the SendAsyncCallback method, should I call sc.Dispose(), or mail.Dispose()?

I checked MSDN document, one example calls MailMessage.Dispose(), but will this dispose method also dispose the SmtpClient instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:07:27+00:00Added an answer on May 22, 2026 at 4:07 pm

    You should dispose both the MailMessage and the SmtpClient in SendAsyncCallback.

    Disposing the MailMessage will not dispose the SmtpClient automatically (because you might want to send two messages with the same SmtpClient, and you wouldn’t want the client to be disposed as soon as you disposed the first message).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use the System.Net.Mail.SmtpClient class to relay an email through my company's
I use asp.net's smtpClient to send email, but recently I found it can only
I'm trying to send an email from a system which is trying to use
So I've been using System.Net.Mail.MailMessage objects for sending e-mail via SmtpClient for a while
I have the following class: public class Email { public System.Net.Mail.SmtpClient SmtpClient { get
In my web app (ASP.NET MVC), I send an email using the following: MailMessage
I assume that web controls (such as the PasswordRecovery control) use SmtpClient to send
I'm trying to send email with C#. Our email provider suggested that I use
I am trying to use the MailMessage class to construct e-mail messages that are
I am trying to use the below code to send email from asp.net(C#). using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.