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

  • SEARCH
  • Home
  • 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 8224193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:58:39+00:00 2026-06-07T14:58:39+00:00

I am trying to send email using the following code and get the error

  • 0

I am trying to send email using the following code and get the error above.

There is two emails being sent the first one seems to get delivered fine, the code below doesn’t seem to work.

Can anyone help please?

        using (var mail = new MailMessage(fromEmail.Trim(), ToEmail.Trim()))
        {
            mail.IsBodyHtml = true;

            bodyText = bodyText.Replace("**Message**", Message);

            // populate the message
            mail.Subject = subject;
            mail.Body = bodyText;

            // send it
            var smtpClient = new SmtpClient();
            smtpClient.Send(mail);
        }

The config:

  <system.net>
    <mailSettings>
      <smtp from="test@foo.com">
        <network defaultCredentials="true" port="25" host="127.0.0.1" password="" userName=""/>
      </smtp>
    </mailSettings>
  </system.net>
  • 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-06-07T14:58:41+00:00Added an answer on June 7, 2026 at 2:58 pm

    instead of placing the MailMessage as the subject of the using block, try making the SmtpClient the subject.

    EDIT:
    If your version of .net is < 4.0, you will need to do some finagling to ensure that the smtp client is disposed before attempting to send another message.

    Assuming that the using block also represents the body of an instance method, a naive test could be:

    1. Create an instance of the containing class

    2. Send the first message via a call to the above-referenced class method

    3. Set the reference = null (in other words, ensure that the SmtpClient has actually been marked/disposed. You may want/need to manually dispose of the instance as a further check)

      Jeff Tucker made the suggestion that you set the SmtpClient.Timeout value to 2 – see his comment for more on this.

    4. Create a new instance of that same class

    5. Send the second message

    Following that (assuming that works), you can iterate the steps to refine and narrow the logic until you’re satisfied with it.

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

Sidebar

Related Questions

I am trying to send email using PHP mail. I get the following error:
I am trying to send email using c# following is my code. try {
I am trying to send an email using the following very standard code. However,
I am trying to send email through gmail using PHPMailer_V5.1. Getting the following error,
I am trying to send an email using c# using the following code. MailMessage
am trying to send an email using the following code $this->load->library('email', $config); $this->email->from('leena.nasir552@gmail.com'); $this->email->to('leena.nasir@morgan.com');
I am trying to send email using apache james with this code public static
I am trying to send email using the following method in my action class:
I'm trying to send a mail using Zend_Mail using the following code: function sendMail()
I'm using Grails Mail plugin and trying to send email and keep getting: Error

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.