Sendmail

Integrate Sendmail with Strapi

Sendmail logo

Why Use Sendmail?

Integrate Sendmail with Strapi to enable instant email capabilities without extra services. Sendmail is the default email provider in Strapi's email plugin, suitable for local development environments. For production use, further configuration or switching to another provider is required.

This simple integration shines during local development when you need to test email features quickly. Think of it as your email training wheels—perfect for getting started with Sendmail in Strapi.

Just remember—Sendmail works best in development. For real-world applications, you'll want to beef up security with DKIM and SPF records or graduate to external email providers for Strapi like SendGrid or Amazon SES.

Checkout the Strapi documenation for the Email plugin.

Why Use Strapi?

Strapi is the leading open-source headless CMS offering features, like customizable APIs, role-based permissions, multilingual support, etc. It simplifies content management and integrates effortlessly with modern frontend frameworks.

Explore the Strapi documentation for more details.

Strapi 5 Highlights

The out-of-the-box Strapi features allow you to get up and running in no time:

  1. Single types: Create one-off pages that have a unique content structure.
  2. Draft and Publish: Reduce the risk of publishing errors and streamline collaboration.
  3. 100% TypeScript Support: Enjoy type safety & easy maintainability
  4. Customizable API: With Strapi, you can just hop in your code editor and edit the code to fit your API to your needs.
  5. Integrations: Strapi supports integrations with Cloudinary, SendGrid, Algolia, and others.
  6. Editor interface: The editor allows you to pull in dynamic blocks of content.
  7. Authentication: Secure and authorize access to your API with JWT or providers.
  8. RBAC: Help maximize operational efficiency, reduce dev team support work, and safeguard against unauthorized access or configuration modifications.
  9. i18n: Manage content in multiple languages. Easily query the different locales through the API.
  10. Plugins: Customize and extend Strapi using plugins.

Learn more about Strapi 5 feature.

Setup Strapi 5 Headless CMS

We are going to start by setting up our Strapi 5 project with the following command:

🖐️ Note: make sure that you have created a new directory for your project.

You can find the full documentation for Strapi 5 here.

Install Strapi

npx create-strapi-app@latest server

You will be asked to choose if you would like to use Strapi Cloud we will choose to skip for now.

 Strapi   v5.6.0 🚀 Let's create your new project

To deploy your project, create a new project on the Strapi Cloud dashboard.

? Please log in or sign up. 
  Login/Sign up 
❯ Skip 

After that, you will be asked how you would like to set up your project. We will choose the following options:

? Do you want to use the default database (sqlite) ? Yes
? Start with an example structure & data? Yes <-- make sure you say yes 
? Start with Typescript? Yes
? Install dependencies with npm? Yes
? Initialize a git repository? Yes

Once everything is set up and all the dependencies are installed, you can start your Strapi server with the following command:

cd server
npm run develop

You will be greeted with the Admin Create Account screen.

003-strapi-5.png

Go ahead and create your first Strapi user. All of this is local so you can use whatever you want.

Once you have created your user, you will be redirected to the Strapi Dashboard screen.

004-strapi-5.png

Publish Article Entries

Since we created our app with the example data, you should be able to navigate to your Article collection and see the data that was created for us.

005-strapi-5.png

Now, let's make sure that all of the data is published. If not, you can select all items via the checkbox and then click the Publish button.

Strapi Articles Published

Enable API Access

Once all your articles are published, we will expose our Strapi API for the Articles Collection. This can be done in Settings -> Users & Permissions plugin -> Roles -> Public -> Article.

You should have find and findOne selected. If not, go ahead and select them.

007-strapi-5.png

Test API

Now, if we make a GET request to http://localhost:1337/api/articles, we should see the following data for our articles.

008-strapi-5.png

🖐️ Note: The article covers (images) are not returned. This is because the REST API by default does not populate any relations, media fields, components, or dynamic zones.. Learn more about REST API: Population & Field Selection.

So, let's get the article covers by using the populate=* parameter: http://localhost:1337/api/articles?populate=*

vuejs strapi integration - api request.png

Getting Started with Sendmail Integration

Ready to send some emails? Strapi supports various email providers through plugins, allowing you to configure services like Sendgrid, Resend, and Mailgun for sending emails. Integration involves installing the appropriate plugin and configuring it within your Strapi project.

Configuring the Strapi Environment

For custom setups, you might need to install the Sendmail provider manually:

Using npm:

npm install @strapi/provider-email-sendmail --save

Or with yarn:

yarn add @strapi/provider-email-sendmail

Keep your sensitive info safe by setting up environment variables. Add these to your .env file:

DEFAULT_FROM_EMAIL=hello@example.com
DEFAULT_REPLY_TO_EMAIL=hello@example.com

Setting up environment variables is crucial not only for email configurations but also when you configure your Strapi database.

Installing and Adjusting Sendmail Settings

Set up Sendmail by creating or updating your ./config/plugins.js file:

module.exports = ({ env }) => ({
  // ...
  email: {
    config: {
      provider: 'sendmail',
      settings: {
        defaultFrom: env('DEFAULT_FROM_EMAIL'),
        defaultReplyTo: env('DEFAULT_REPLY_TO_EMAIL'),
      },
    },
  },
  // ...
});

This setup pulls values from your environment variables, making your config adaptable across different systems.

Code Implementation to Integrate Sendmail With Strapi

Whether you're coding in JavaScript or exploring TypeScript vs JavaScript with Strapi, sending emails is straightforward with Strapi.

With everything configured, sending emails using Strapi's email plugin can be straightforward. Ensure you have the correct JavaScript code to initiate the email sending process.

Want better email delivery rates? Add DKIM:

To generate your DKIM records easily, consider using one of these DKIM record generators.

With your email sending capability set up, you might also want to explore email automation in Strapi to streamline your workflows.

Sendmail works well for development, but for serious production use, consider switching to SendGrid, Mailgun, or Amazon SES—especially when sending loads of emails or needing detailed analytics.

Strapi Open Office Hours

If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at Strapi's Discord Open Office Hours Monday through Friday at 12:30 pm - 1:30 pm CST: Strapi Discord Open Office Hours

For more details, visit the Strapi documentation.

Frequently Asked Questions

Sendmail is Strapi's default email provider suitable for local development and testing. It sends emails through your server's mail transfer agent without requiring external service configuration.

Sendmail works out of the box as Strapi's default provider. For custom settings, update your plugins.js file with sender addresses stored in environment variables for flexibility across environments.

Sendmail lacks deliverability features, analytics, and reputation management that production email requires. Emails may be marked as spam without proper DKIM and SPF records. Upgrade to services like SendGrid, Mailgun, or Amazon SES for production.

Yes, Sendmail requires a mail transfer agent installed on your server. Many development environments include this by default, but cloud platforms may not, requiring alternative configuration.

Install the provider plugin for your chosen service (SendGrid, Mailgun, etc.), configure credentials in your plugins.js file, and update environment variables. The email plugin API remains the same, so no code changes are needed.