These integration guides are not official documentation and the Strapi Support Team will not provide assistance with them.
Why Use Mailjet
Mailjet is a comprehensive email service provider that combines powerful features with developer-friendly tools, making it an excellent choice for both marketing and transactional emails. Some of its main features and benefits include: robust API infrastructure, advanced analytics, developer-friendly integration, automation tools, event tracking and more.
For detailed implementation guides and API references, visit the Mailjet documentation.
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. Customizable API: With Strapi, you can just hop in your code editor and edit the code to fit your API to your needs. 3. Integrations: Strapi supports integrations with Cloudinary, SendGrid, Algolia, and others. 4. Editor interface: The editor allows you to pull in dynamic blocks of content. 5. Authentication: Secure and authorize access to your API with JWT or providers. 6. RBAC: Help maximize operational efficiency, reduce dev team support work, and safeguard against unauthorized access or configuration modifications. 7. i18n: Manage content in multiple languages. Easily query the different locales through the API.
Learn more about Strapi 5.
Try the Live Demo
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
We can't find any auth credentials in your Strapi config.
Create a free account on Strapi Cloud and benefit from:
- ✦ Blazing-fast ✦ deployment for your projects
- ✦ Exclusive ✦ access to resources to make your project successful
- An ✦ Awesome ✦ community and full enjoyment of Strapi's ecosystem
Start your 14-day free trial now!
? 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.
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.
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.
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.
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.
Test API
Now, if we make a GET
request to http://localhost:1337/api/articles
, we should see the following data for our articles.
🖐️ 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=*
Getting Started with Mailjet
When integrating Mailjet with Strapi, implementing proper testing and error handling strategies is crucial for ensuring reliable email delivery. Let's explore comprehensive approaches to testing, troubleshooting, and maintaining your email functionality.
Testing Strategies
To ensure your Mailjet integration works reliably, implement these testing methods:
- Unit Testing
- Test individual email service functions
- Verify input handling and expected outputs
- Use testing frameworks like Jest or Mocha
- Integration Testing
- Test actual email sending through Mailjet API
- Verify API response codes
- Confirm proper email content formatting
- User Acceptance Testing (UAT)
- Send test emails to various email providers (Gmail, Yahoo, etc.)
- Check inbox placement, spam folder, and promotions tab
- Use tools like Mailtrap or Litmus to analyze email rendering across different clients
Common Issues and Solutions
Here are frequent challenges you might encounter and how to resolve them:
- Authentication Errors
- Symptom: API calls failing with authentication errors
- Solution: Verify your Mailjet API key and secret in your environment variables
- Double-check API version compatibility
- Email Formatting Problems
- Symptom: Emails not rendering correctly
- Solution: Use Mailjet's template editor for testing
- Validate HTML using W3C Validator
- Delivery Failures
- Symptom: Emails not reaching recipients
- Solution: Verify sender domain authentication (SPF and DKIM records)
- Check Mailjet logs for specific delivery issues
Error Handling and Debugging
Implement these error handling practices:
- Error Capture
1try {
2
3 await strapi.plugins['email'].services.email.send({
4 to: 'valid email address',
5 from: 'your verified email address', //e.g. single sender verification in SendGrid
6 cc: 'valid email address',
7 bcc: 'valid email address',
8 replyTo: 'valid email address',
9 subject: 'The Strapi Email plugin worked successfully',
10 text: 'Hello world!',
11 html: 'Hello world!',
12 }),
13} catch (error) {
14 console.error('Email sending failed:', error);
15 // Log error details for debugging
16}
- API Response Monitoring
- Track Mailjet API response codes
- 200: Success
- 400s: Client-side errors
- 500s: Server-side issues
- Debugging Tools
- Use Postman for API request testing
- Monitor email logs in Mailjet dashboard
- Implement detailed error logging in your application
Best Practices
Follow these guidelines for optimal email functionality:
- Template Management
- Regularly test email templates across different devices
- Maintain a library of pre-tested templates
- Version control your email templates
- Environment Setup
- Use separate development and production API keys
- Set up a staging environment for testing
- Never test with production credentials in development
- Performance Monitoring
- Track delivery rates and bounce rates
- Monitor email open rates and click-through rates
- Set up alerts for unusual patterns or failures
For more detailed information about Mailjet's capabilities and integration options, refer to the Mailjet Documentation and Strapi Documentation.
Remember to implement these practices incrementally and maintain thorough documentation of your testing procedures and error handling strategies. Regular monitoring and maintenance of your email system will ensure reliable delivery and optimal performance.
Awesome, great job!
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 and Mailjet documentation.