All preview environments are limited to 12,000 email credits per calendar month.
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:- In the Console
- Using the CLI
- Select the project with the given environment.
- From the Environment menu, select the environment.
- Click Settings.
- In the row with Outgoing emails, click Edit .
- Select the Email sending checkbox.
2. Recommended: Improve deliverability
Improve deliverability of your email with Sender Policy Framework (SPF). If you don’t have an SPF record, add the followingTXT record to your domain’s DNS records:
TXT records isn’t supported due to rfc4408 section 3.1.2.
If you already have an SPF record, please add SendGrid into your existing record.
3. (Optional) Validate your email
You can request for DomainKeys Identified Mail (DKIM) to be enabled on your domain. DKIM improves your delivery rate as an email sender. Learn more about how DKIM works. To have DKIM enabled for your domain:- Open a support ticket with the domain where you want DKIM.
- Update your DNS configuration with the
CNAMEandTXTrecords that you get in the ticket.
TXT record looks similar to the following:
4. Test the email service
To test the email service, use the CLI to connect to your app by runningupsun ssh.
Run the following command:
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.
See some examples for given languages.
- PHP
- 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.Note that the From header is required.
Your email isn’t sent if that 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.