Send e-mails through the SMTP relay

Enable the SMTP relay of your website, SMTP settings, code examples, sender domains, DKIM, logs and queue.

Applications hosted with us can send e-mails — registration confirmations, password resets, contact forms, order confirmations. On Premium every website has its own SMTP relay: an authenticated, encrypted SMTP server that you switch on in the Control Panel. It sends from your own domain, signs messages with DKIM and shows you statistics, logs and the queue of your e-mails.

Option Plan Authentication Best for
SMTP relay of your website Premium Login and password of the relay Sending from your application — the recommended way
Your mailbox on our mail server Premium with e-mail hosting Mailbox login Messages that should also appear as sent by a real mailbox
External SMTP service (for example Gmail) Free and Premium Depends on the service The Free plan

Important

The SMTP relay has to be enabled in the Control Panel before your application can send, and it always requires a login, a password and an encrypted connection. The earlier setup — port 25 without authentication and without SSL — is no longer the way to send e-mails; see Moving from the old local SMTP server.

Enable the SMTP relay

  1. Connect your own domain

    E-mails are sent from your own domain. Our shared free subdomains (runasp.net, tryasp.net, premiumasp.net) cannot be used as the sender, so the relay can be enabled only for a website with its own domain. See Add a custom domain.

  2. Open SMTP relay

    In the Control Panel go to Websites, open your website and choose SMTP relay in the menu (or the SMTP relay tile on the Overview page).

  3. Switch it to Enabled

    In the SMTP Relay settings card click Enabled. The SMTP account of the website is created and its password is generated and shown right away.

  4. Copy the settings into your application

    Use the Server, Port, Login and Password from the card. The Code examples card below contains ready-to-paste code for SmtpClient, MailKit, Node.js and PHP, already filled in with the server, login and domain of your website.

On the Free plan the page shows the settings card for preview only. Upgrade to Premium to switch the relay on, or use an external SMTP server — see Send e-mails through Gmail.

SMTP settings

Setting Value
SMTP server The server name of your website, siteXXXX.siteasp.net — always use the name, not the IP address
Port 587 with STARTTLS (recommended) or 465 with SSL/TLS
Encryption Required — plain, unencrypted connections are refused
Login Shown in the Login field. One SMTP account for the whole website, the same login for every sender domain
Password Generated by the Control Panel. Click Show to display it, Generate to replace it with a new one
Sender (FROM) Any address on one of the sender domains of the website, for example noreply@yourdomain.com

The hourly sending limit of your account is shown in the Limits row of the same card.

Warning

Generate creates a new password and the old one stops working immediately. Update the password in your application right after you generate a new one.

Code examples

The examples read the password from the SMTP_PASSWORD environment variable, so that it is not stored in your source code. Add the variable on the Scripting → Environment variables page of your website — see Environment variables — or read the password from the configuration of your application.

SmtpClient (.NET and .NET Framework)

Built into .NET, no package needed. System.Net.Mail supports STARTTLS on port 587 only; it cannot use SSL/TLS on port 465.

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

using (var client = new SmtpClient("siteXXXX.siteasp.net", 587))
using (var message = new MailMessage("noreply@yourdomain.com", "recipient@example.com"))
{
    client.EnableSsl = true; // STARTTLS on port 587
    client.Credentials = new NetworkCredential("your-smtp-login", Environment.GetEnvironmentVariable("SMTP_PASSWORD"));

    message.Subject = "Hello from yourdomain.com";
    message.Body = "This e-mail was sent through the SMTP relay.";

    client.Send(message);
}

A modern library with full STARTTLS and SSL/TLS support. Install it with dotnet add package MailKit.

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

var message = new MimeMessage();
message.From.Add(new MailboxAddress("My website", "noreply@yourdomain.com"));
message.To.Add(MailboxAddress.Parse("recipient@example.com"));
message.Subject = "Hello from yourdomain.com";
message.Body = new TextPart("plain") { Text = "This e-mail was sent through the SMTP relay." };

using (var client = new SmtpClient())
{
    // port 587 = STARTTLS (recommended), or 465 with SecureSocketOptions.SslOnConnect
    await client.ConnectAsync("siteXXXX.siteasp.net", 587, SecureSocketOptions.StartTls);
    await client.AuthenticateAsync("your-smtp-login", Environment.GetEnvironmentVariable("SMTP_PASSWORD"));
    await client.SendAsync(message);
    await client.DisconnectAsync(true);
}

Node.js (Nodemailer)

Install it with npm install nodemailer.

const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
  host: "siteXXXX.siteasp.net",
  port: 587,
  secure: false, // STARTTLS on port 587; use port 465 with secure: true for SSL/TLS
  auth: {
    user: "your-smtp-login",
    pass: process.env.SMTP_PASSWORD,
  },
});

transporter
  .sendMail({
    from: '"My website" <noreply@yourdomain.com>',
    to: "recipient@example.com",
    subject: "Hello from yourdomain.com",
    text: "This e-mail was sent through the SMTP relay.",
  })
  .then((info) => console.log("Sent:", info.messageId))
  .catch((err) => console.error("Send failed:", err));

PHP (PHPMailer)

Works with plain PHP, Laravel, WordPress and most frameworks. Install it with composer require phpmailer/phpmailer.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);
try {
    $mail->isSMTP();
    $mail->Host       = 'siteXXXX.siteasp.net';
    $mail->Port       = 587;                              // or 465 with PHPMailer::ENCRYPTION_SMTPS
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->SMTPAuth   = true;
    $mail->Username   = 'your-smtp-login';
    $mail->Password   = getenv('SMTP_PASSWORD');          // or read it from your config file
    $mail->CharSet    = 'UTF-8';

    $mail->setFrom('noreply@yourdomain.com', 'My website');
    $mail->addAddress('recipient@example.com');
    $mail->Subject = 'Hello from yourdomain.com';
    $mail->Body    = 'This e-mail was sent through the SMTP relay.';

    $mail->send();
    echo 'Sent';
} catch (Exception $e) {
    echo 'Send failed: ' . $mail->ErrorInfo;
}

Sender domains

The Sender domains card lists the domains allowed in the FROM address. The FROM address of every e-mail must be on one of them — e-mails from any other domain are rejected by the relay and appear in the Accepted log as rejected.

  • The main domain of the website is added when you enable the relay.
  • To send from another domain, first connect it to the website, then pick it under Add sender domain and click Add.
  • Remove takes a domain off the list; e-mails with a FROM address on that domain are then rejected.

You can use any address on a sender domain (noreply@, info@, orders@…); the mailbox does not have to exist. If you want to receive replies, use an address that does exist, or set a Reply-To header.

DKIM

DKIM adds a cryptographic signature to every e-mail, so that the recipient's mail server can verify that the message really comes from your domain. Gmail, Outlook.com and Yahoo expect it; without DKIM your messages are far more likely to end up in spam.

Switch DKIM to On next to each sender domain. The signature needs a DNS TXT record, which is shown under the domain:

  • Your domain uses our name servers — the record is published automatically, there is nothing more to do.
  • Your DNS is hosted elsewhere (for example at Cloudflare) — copy the Name and Value of the record to your DNS provider, wait until the change propagates and click Check DNS again. The badge next to the record tells you whether the record was found and whether it matches.

SPF record

SPF tells other mail servers that the server of your website is allowed to send e-mails for your domain. Add the server of your website to the SPF TXT record of the domain:

Name Type Value
@ (or yourdomain.com) TXT v=spf1 a:siteXXXX.siteasp.net ~all

A domain can have only one SPF record. If the domain already has one — for example for our e-mail hosting — add a:siteXXXX.siteasp.net to it instead of creating a second record:

v=spf1 a mx include:spf.mailasp.net a:siteXXXX.siteasp.net ~all

Statistics, logs and queue

Once the relay is enabled, the same page shows what happened to your e-mails:

Section What it shows
Sent e-mails Numbers of accepted, delivered and bounced e-mails, with a day-by-day overview (days are in UTC).
Accepted Messages your application handed over to the relay, including those the relay rejected — for example because of a FROM address outside the sender domains.
Delivery Every delivery attempt with the answer of the recipient's mail server. Bounced means the address was rejected permanently; remove it from your mailing lists to protect your sender reputation.
Queue E-mails still waiting to be delivered. Deferred means the recipient's server asked us to try again later; the relay retries automatically for up to 24 hours.

The logs can be filtered to the last 24 hours, 7 days or 30 days.

Alternative: your mailbox on our mail server

If you have e-mail hosting for your domain, your application can also send through the mail server with the login of one of your mailboxes. Messages are signed with DKIM once DKIM is enabled for the e-mail domain.

Setting Value
SMTP server Your mail server, mailXXX.mailasp.net (shown in the Control Panel under E-mails → your domain → Overview, in the Server field)
Port 587 with STARTTLS (or 465 with SSL/TLS)
Username The full e-mail address of the mailbox
Password The password of the mailbox
var smtp = new SmtpClient("mailXXX.mailasp.net", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("info@yourdomain.com", "mailbox-password");

Warning

Set UseDefaultCredentials = false before you assign Credentials. In the opposite order the credentials are cleared and the server rejects the message.

A mailbox can send up to 300 e-mails per hour; see E-mail service limits.

Moving from the old local SMTP server

Earlier, a Premium website could send through the local SMTP server on port 25 without a login. This is replaced by the SMTP relay. To update an existing application:

  1. Enable the SMTP relay for the website as described above.
  2. Keep the same server name, siteXXXX.siteasp.net, and change the port from 25 to 587.
  3. Turn encryption on (EnableSsl = true, STARTTLS).
  4. Add the login and password of the relay.
  5. Make sure the FROM address is on one of the sender domains, and switch DKIM on.

Protect your contact form

Never publish a contact form without protection. Bots fill in unprotected forms thousands of times, which sends spam from your domain and damages its reputation. Add a CAPTCHA such as Cloudflare Turnstile or Google reCAPTCHA to every public form.

E-mails are not arriving?

  • The application cannot connect or log in — check that the relay is Enabled, that you use port 587 with STARTTLS (or 465 with SSL/TLS) and the current password. Log the exception thrown by your SMTP library; it contains the answer of the server.
  • The message is rejected when sending — the FROM address is not on one of the sender domains. Look at the Accepted log.
  • The message was accepted but did not arrive — open the Delivery log and read the answer of the recipient's server; check the Queue for messages that are still being retried.
  • The message ends up in spam — switch DKIM on, check that its DNS record is published and add the SPF record. See also E-mails land in spam or are rejected.
Still stuck? Our support team is happy to help.
Ask the community Open a support ticket