Skip to main content
You can configure your Upsun environments to send emails through an SMTP proxy. Emails aren’t guaranteed to be deliverable and you can’t white-label them. The SMTP proxy is intended as a zero-configuration, best-effort service.
Each preview environment (a development or staging environment) has its own SendGrid sub-user, so the 12,000 email credits per calendar month limit applies individually per environment, not as a shared pool across your project.

1. Turn on outgoing email

You can turn on outgoing email for each environment. By default, email is turned on for your Production environment and blocked for other environments. To turn it on for a specific environment, follow these steps:
  1. Select the project.
  2. Select the environment from the Environment menu.
  3. Click Settings.
  4. On the General tab, select the Enable outgoing emails checkbox.
To turn off outgoing email, clear the Enable outgoing emails checkbox.
Changing the setting rebuilds the environment. Improve deliverability of your email with Sender Policy Framework (SPF). If you don’t have an SPF record, add the following TXT record to your domain’s DNS records:
Having several, conflicting TXT records isn’t supported due to rfc4408 section 3.1.2. If you already have an SPF record, add SendGrid to your existing record.

3. (Optional) Validate your email

You can request DomainKeys Identified Mail (DKIM) validation for your domain. DKIM improves your delivery rate as an email sender. Learn more about how DKIM works. To have DKIM enabled for your domain:
  1. Open a support ticket and request the following, replacing <SENDER_EMAIL_ADDRESS> with the address you send from:
    The DKIM domain might not be the same as your site domain (but it can be). DKIM needs to be generated on the domain of the <SENDER_EMAIL_ADDRESS> you provide above (the sender address), not necessarily your site’s domain. For example, if <SENDER_EMAIL_ADDRESS> is noreply@media.yourdomain.com, request DKIM for media.yourdomain.com, not yourdomain.com.Make sure you’ve sent at least one email before requesting DKIM.
  2. Add the CNAME and TXT records from the support team’s reply to your domain’s DNS configuration. The reply looks similar to the following:
    This TXT record replaces the generic one from step 2 — as part of DKIM setup, SendGrid provides a unique SPF record for your domain instead of the generic one. Checks for the expected DNS records run every 15 minutes. After SendGrid detects the records, it confirms them automatically — you don’t need to take any further action.
    SendGrid rotates DKIM keys on an internal schedule that it doesn’t publish, and offers no manual rotation option — the process is entirely transparent to you.

4. Test the email service

To test the email service, use the CLI to connect to your app by running upsun ssh. Run the following command:
Replace the variables with actual email addresses as in the following example:
Check the recipient’s inbox, including the spam folder — the test message should arrive within a few minutes.
When sending emails from your project, use an address on the same domain you requested DKIM for (see the domain note above), otherwise the message will be flagged as a spoofing attempt and not be sent.Also, make sure to test with real email addresses. If you send emails to fake domains (such as example.com), they fail and hurt your sending reputation. Make sure your test emails are deliverable.

5. Send email from your app

You can use /usr/sbin/sendmail on your app container to send emails as with the example in the previous step. Or use the PLATFORM_SMTP_HOST environment variable in your SMTP configuration. When outgoing emails are on, PLATFORM_SMTP_HOST is the address of the SMTP host that should be used. When outgoing emails are off, the variable is empty. When using PLATFORM_SMTP_HOST, send email through port 25 (often the default). Your emails are proxied through the Upsun SMTP host and encrypted over port 465 before being sent to the outside world. The precise way to send email depends on the language and framework you use. The following examples show PHP and Java.
To send email in PHP, you can use the built-in mail() function. The PHP runtime is configured to send email automatically with the correct configuration. This works even for libraries such as PHPMailer, which uses the mail() function by default.The From header is required. Your email will not be sent if the header is missing.Beware of potential security problems when using the mail() function. If you use any input from users in the $additional_headers or $additional_params parameters, be sure to sanitize it first.

Alternative: Use a different email server

If you need more options, use your own SMTP server or email delivery service provider. Remember that TCP port 25 is blocked for security reasons. Use port 465 or 587 instead to send email to your own external email server.
Last modified on August 10, 2026