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 7938159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:43:38+00:00 2026-06-03T22:43:38+00:00

I am having an error that is occurring sporadically. When I encounter this error,

  • 0

I am having an error that is occurring sporadically. When I encounter this error, if I try again, the e-mail will send. I cannot reliably reproduce the error, but it is hapening frequently enough to be a problem.

System.Net.Mail.SmtpException : Service not available, closing transmission channel. The server response was: [Servername]: SMTP command timeout – closing connection

Stack Trace:

at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)

Here’s the code in question. It uses an HTML template (database driven with a web url default backup) to inject values and create an html e-mail.

public void AccountActivationEmail(Common.Request.Email.AccountActivation request)
{
    var profile = profileRepository.GetOne(new ProfileByUsername(request.Username, request.SiteId));
    var options = siteService.GetOptions(new GatewayOptionsRequest()
    {
        SiteId = request.SiteId
    });
    var site = options.Site;

    ExpiringHMAC hmac = new ExpiringHMAC(request.ExpireOn, new string[] { request.AccountId.ToString(), request.AccountKey.ToString(), request.Username });

    Dictionary<string, string> data = new Dictionary<string, string>();

    data.Add("{{logourl}}", String.IsNullOrEmpty(options.FullyHostedGateway.LogoUrl) ? UrlHelper.ConvertRelativeToAbsolute("/content/images/spacer.png") : options.FullyHostedGateway.LogoUrl);
    data.Add("{{name}}", profile.Name.DisplayName);
    data.Add("{{sitename}}", site.Name.DisplayName);
    data.Add("{{activationlink}}", String.Format(ActivationUrlFormat, options.UrlFriendlyName, Encryption.EncryptQueryString(request.Username), hmac.ToString()));

    MailDefinition template = new MailDefinition();
    MailMessage message = null;
    var emailTemplate = options.GetEmailTemplate(EmailTemplateType.ActivateAccount);
    string defaultSubject = "Activate Account";

    bool hasTemplate = false;

    if (emailTemplate != null)
    {
        hasTemplate = !String.IsNullOrEmpty(emailTemplate.Template);
    }

    if (!hasTemplate)
    {
        template.BodyFileName = activationDefaultTemplateUrl;
        message = template.CreateMailMessage(request.EmailAddress, data, new System.Web.UI.LiteralControl());
        message.IsBodyHtml = true;
        message.Subject = defaultSubject;
    }
    else
    {
        message = template.CreateMailMessage(request.EmailAddress, data, emailTemplate.Template, new System.Web.UI.LiteralControl());
        message.IsBodyHtml = emailTemplate.IsHtml;

        if (!String.IsNullOrEmpty(emailTemplate.Subject))
            message.Subject = emailTemplate.Subject;
        else
            message.Subject = defaultSubject;
    }

    if (options.ContactDetails != null)
    {
        if (!String.IsNullOrEmpty(options.ContactDetails.EmailAddress))
            message.From = new MailAddress(options.ContactDetails.EmailAddress);
    }

    SmtpClient client = new SmtpClient();

    client.Send(message);
}

This code is part of a class that is generated as a singleton using Structuremap. I thought maybe that might be causing the issue, but every time the method is called, a new SmtpClient object is created, which should eliminate the problems I have seen about using the same connection to send multiple e-mails.

We have nothing blocking or restricting the connection, which is the official stance our e-mail hosting is taking on this issue. I want to see if there’s any way to do this better so I don’t get these errors.

EDIT:

I do have my mail server defined in my web.config. I have confirmed with my e-mail hosting that my settings are correct.

  <system.net>
      <mailSettings>
        <smtp deliveryMethod="Network" from="no-reply@mydomain.com">
          <network host="smtp.emailhost.com" userName="someaddress@mydomain.com" 
              password="myPassword1" port="2500" />
        </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-03T22:43:39+00:00Added an answer on June 3, 2026 at 10:43 pm

    Are you disposing of the Smtp Client object after sending? From http://connect.microsoft.com/VisualStudio/feedback/details/337557/smtpclient-does-not-close-session-after-sending-message it would appear that “…even if you are creating a new instance of the SmtpClient every time, it still uses the same unerlying session.”

    So perhaps

    using (SmtpClient client = new SmtpClient())
    {
        client.Send(message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an sql error that i can't work out. I have to update
here is the part if having error. Fatal error: Using $this when not in
I`m having the following error . Why am I having this error and how
I am having this error in my j2ee web application. java.sql.SQLException: ORA-00604: error occurred
I'm totally new to C# and I'm having an error that I can't guess
I'm having a problem with Jet throwing error 3011 when I try to use
I am having a very odd error occurring in the following: class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): def
This stack trace comes as a result of an error that reads Provider name
Im having an error that says: Request-URI Too Large Actually I'm trying to add
I have a method that looks like this: try { doStuff(); } catch (Exception

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.