4 min read Sep 26, 2026

How to Send Email from ASP.NET and Classic ASP (SMTP Settings)

Send contact-form and order emails from ASP.NET or Classic ASP through your FimuroHost mailbox, with working System.Net.Mail, MailKit and CDOSYS code.

FimuroHost Team

FimuroHost Team

Technical Writer

Share Article

Contact forms, order confirmations and password resets on your Windows Hosting site should be sent through a real mailbox on your domain using authenticated SMTP. That way messages are signed by our mail servers, pass SPF and DKIM checks, and land in the inbox rather than spam.

Email on Windows Hosting uses the same StackCP mail service as our Cloud Hosting, so the settings are the same.

Before you start

  1. In StackCP, create a mailbox to send from, for example [email protected] or [email protected] (see How to Create Professional Email with Your Domain).
  2. Log in to webmail once with it and send a test message, to confirm the password works.
  3. Make sure your domain has an SPF record that includes our mail servers and that DKIM is enabled (see How to Set Up DKIM in StackCP).

SMTP settings

SettingValue
SMTP serversmtp.stackmail.com
Port587 with STARTTLS, or 465 with SSL/TLS from the start
AuthenticationRequired
UsernameThe full email address
PasswordThat mailbox's password

ASP.NET with System.Net.Mail

The built-in SmtpClient only supports STARTTLS, so use port 587 with it. (It can't use port 465.)

using System.Net;
using System.Net.Mail;

// Only needed for apps whose web.config targets .NET Framework below 4.7:
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

using (var msg = new MailMessage())
{
    msg.From = new MailAddress("[email protected]", "Your Website");
    msg.To.Add("[email protected]");
    msg.ReplyToList.Add(new MailAddress(visitorEmail));   // the person who filled in the form
    msg.Subject = "New contact form message";
    msg.Body = "Name: " + visitorName + "\n\n" + visitorMessage;

    using (var smtp = new SmtpClient("smtp.stackmail.com", 587))
    {
        smtp.EnableSsl = true;   // STARTTLS on port 587
        smtp.Credentials = new NetworkCredential("[email protected]", "MailboxPassword");
        smtp.Send(msg);
    }
}

You can keep the server details in web.config instead of code; new SmtpClient() with no arguments then reads them:

<system.net>
  <mailSettings>
    <smtp from="[email protected]" deliveryMethod="Network">
      <network host="smtp.stackmail.com" port="587" enableSsl="true"
               userName="[email protected]" password="MailboxPassword"
               defaultCredentials="false" />
    </smtp>
  </mailSettings>
</system.net>

ASP.NET with MailKit (recommended for new code)

Microsoft recommends MailKit for new development. Install it from NuGet (Install-Package MailKit); it supports .NET Framework 4.6.2 and later, and both ports:

using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;

var message = new MimeMessage();
message.From.Add(new MailboxAddress("Your Website", "[email protected]"));
message.To.Add(MailboxAddress.Parse("[email protected]"));
message.ReplyTo.Add(MailboxAddress.Parse(visitorEmail));
message.Subject = "New order #1042";
message.Body = new TextPart("plain") { Text = "A new order has been placed." };

using (var client = new SmtpClient())   // MailKit's SmtpClient, not System.Net.Mail's
{
    client.Connect("smtp.stackmail.com", 465, SecureSocketOptions.SslOnConnect);
    // or: client.Connect("smtp.stackmail.com", 587, SecureSocketOptions.StartTls);
    client.Authenticate("[email protected]", "MailboxPassword");
    client.Send(message);
    client.Disconnect(true);
}

Classic ASP with CDOSYS

Classic ASP sends mail with the built-in CDO component. CDO works with SSL from the start, so use port 465:

<%
Const cdoSchema = "http://schemas.microsoft.com/cdo/configuration/"
Dim cfg, msg
Set cfg = Server.CreateObject("CDO.Configuration")
With cfg.Fields
  .Item(cdoSchema & "sendusing") = 2                  ' send via SMTP server
  .Item(cdoSchema & "smtpserver") = "smtp.stackmail.com"
  .Item(cdoSchema & "smtpserverport") = 465
  .Item(cdoSchema & "smtpusessl") = True
  .Item(cdoSchema & "smtpauthenticate") = 1           ' basic authentication
  .Item(cdoSchema & "sendusername") = "[email protected]"
  .Item(cdoSchema & "sendpassword") = "MailboxPassword"
  .Item(cdoSchema & "smtpconnectiontimeout") = 30
  .Update
End With

Set msg = Server.CreateObject("CDO.Message")
Set msg.Configuration = cfg
msg.From = "Your Website <[email protected]>"
msg.To = "[email protected]"
msg.ReplyTo = Request.Form("email")
msg.Subject = "New contact form message"
msg.TextBody = Request.Form("message")
msg.BodyPart.Charset = "utf-8"
msg.Send

Set msg = Nothing : Set cfg = Nothing
%>

Good practice

  • Always send From your own mailbox. Never put the visitor's address in From; Gmail and others reject that because of DMARC. Put it in Reply-To so you can simply press Reply.
  • Don't hard-code the password in many pages. Keep it in one place (web.config or a single include file) and protect that file.
  • Protect your forms with a CAPTCHA or honeypot field and validate input, or spammers will use your form to send through your mailbox and it may be paused.
  • Know the limits. Sending limits apply to each mailbox, and new mailboxes have a lower limit for their first week. See Email Sending Limits. For newsletters, use a dedicated email marketing service.

Common problems

  • “The SMTP server requires a secure connection or the client was not authenticated” – wrong password, or EnableSsl is false. Test the same login in webmail.
  • Timeout when using SmtpClient on port 465 – switch to port 587; System.Net.Mail doesn't support port 465.
  • “Authentication failed because the remote party has closed the transport stream” – TLS 1.2 isn't enabled for an older app. Add the ServicePointManager line above, or set <httpRuntime targetFramework="4.8" />.
  • CDO error 0x80040213 “The transport failed to connect to the server” – check the port is 465 and smtpusessl is True.
  • Mail sends but lands in spam – check SPF and DKIM; see How to Stop Your Emails Going to Junk or Spam.

More general help: Can't Send Email? Settings, Limits and Fixes.

Need help?

If something doesn't work as described, open a support ticket from your client area or message us on WhatsApp at 01818160926. Include the full error message and the mailbox you send from (never the password).

Categories

FimuroHost Team

Written by

FimuroHost Team

Technical Writer