This is an example of how to set up a Node.js application to send emails via SendGrid from Kinsta’s Application Hosting services.

Kinsta does not natively support outbound emails from servers. Sending emails through specialized outbound providers such as SendGrid or Mailchimp offers more flexibility and higher success rates for transactional and campaign emails.

  1. Fork this GitHub repository: Kinsta – Hello World – Email Sending With Node.js
  2. In MyKinsta, add an application with the Hello World – Email Sending With Node.js. In Environment variables, add the following:
    • SENDGRID_API_KEY: The API key from SendGrid.
    • TEST_EMAIL_TO_ADDRESS: The address you’d like to send the test email to.
    • TEST_EMAIL_FROM_ADDRESS: The address you’d like to send the test email from.
    • TEST_ENDPOINT: The endpoint you’d like to use as a trigger to send the test email. Use a random string of at least 8 characters.
  3. The Start command can be left blank for the web process as Kinsta automatically detects the required command during the first deployment.

The app is available as soon as the build finishes and a Hello World page loads at your application’s URL.

Node.js email sending Hello World page after successful installation.
Node.js email sending Hello World page after successful installation.

Trigger an Email

This project does not require a build phase. The start command runs node server.js, which starts an Express server with two endpoints:

  • /: A simple page that returns the Hello World message
  • /${TEST_ENDPOINT}: A page that triggers a test email.

To trigger an email, find the URL of your deployment on the Deployments page, append your test endpoint to this URL, and visit the page. For example, if your TEST_ENDPOINT is set to o34nifnodhni4of and your latest deployment is at https://example.kinsta.app you can trigger a test email from https://example.kinsta.app/o34nifnodhni4of in your browser.

An “Email sent” message appears if the test email is successful.

Node.js email sent message.
Node.js email sent message.

If you verify this at SendGrid, you also get a successful message.

Test email received at SendGrid.
Test email received at SendGrid.