Investigation about migrating from Gmail to SendGrid
- Introduction
- Goals and quick answer
- Price-details
- deploy-to-test
- API
- design the new development flow to deploy and update the email templates
Introduction
Now we are using Gmail workspace
in project, which includes OTP(One-time-password)
, notification and other services by email.
However, due to the large number of activity notifications in the project, email sending may reach the limitation of 2000 emails per day.
The overage price is not attractive.
Besides, Gmail workspace
email service is not designed for handling large volumes of marketing-like emails, and it has its own throttling mechanisms.
So we need to investigate integrating SendGrid
.
Goals and quick answer
Clarify the following key questions:
The limitation/day of the SendGrid, and if we are out of the limit, what's the limitation and price?
$19.95/month, basic 50k/month, $0.00133 per additional email check Price-details to know more
What extra work needs FE and BE to do if we modify the email service from Gmail to SendGrid.
- BE integrate @sendgrid/mail, config domain and test, check deploy to test
- A new deployment flow is required, to make sure we could maintain the emails templates in different version.
The email compatibility(most of the email send services will do some modify to the html files)
good. I have tested on gmail-website, gmail-IOS-app, mac-email-app
Can we test email context, just as with
Mailosaur
It depends what detail we want to test.
We could test to know that we have send the email, but may not be able to test the variable send by BE, such as the
verification code
.
Price-details
Google compare with SendGird:
SendGrid API | Google workspace | |
---|---|---|
usage | 50k emails/month | 2k emails/day |
price | $19.95 / month | |
overage rates | $0.00133 per additional |
SendGrid prices:
type | usage | price | overage rates |
---|---|---|---|
Essentials1 | 50k emails/month | $19.95/month | $0.00133 per additional email |
Essentials2 | 100k emails/month | $34.95/month | $0.0009 per additional email |
Pro | 100k emails/month | $89.95/month | $0.0011 per additional email |
Pro | 300K emails/month | $249.00/month | $0.00091 per additional email |
Pro | 700K emails/month | $499.00/month | $0.00078 per additional email |
Other SendGrid Prices - check from their website
deploy-to-test
sign uo and login https://app.sendgrid.com/, fill the required information.
validate private email(only for test)/config the domain
- test with private email
Setting > Sender Authentication > Single Sender Verification
, fill your private emailxxx@gmail.com
, then the node env test API will send email with your test email. - deploy to test, require validate domain and config domain
- test with private email
config the email templates(html file) to send
- send with templates:
then, try this:
const sgMail = require('@sendgrid/mail'); sgMail.setApiKey(OUR_APIKEY); const sendWithTemplate = { to: 'chase.wu1990@gmail.com', from: 'chase.wu1990@gmail.com', templateId: 'd-7c578e6a094a4129a14f9cc2b08901fb', dynamicTemplateData: { subject: 'Testing Templates', fullName: "Chase", bucketName: '93f06186-0d7c-4bf0-9ed3-596a7d4aa7af_develop', reasonSuspension: "Explicit contents", facebook_link: "https://www.facebook.com/", instagram_link: "https://www.instagram.com/", youtube_link: "https://www.youtube.com/", linkedin_link: "https://www.linkedin.com/", twitter_link: "https://www.linkedin.com/", email: "test@aladia.io", updateLink: "https://docs.aladia.io", courseThumbnail: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHVfnpm7srBabzA86MrYHqeoF6-xsSSZKXDQ&s", userAvatar: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHVfnpm7srBabzA86MrYHqeoF6-xsSSZKXDQ&s", titleDescription: "Title Description", expirationTime: "2 hours", verificationCode: "321937" }, }; sgMail.send(sendWithTemplate).then((res) => { console.log(res); }).catch((error) => { console.error(error); });
- send with local file, we need to hand to place the variables in html by ourself
const sgMail = require('@sendgrid/mail'); const fs = require('fs'); const path = require('path'); sgMail.setApiKey(OUR_APIKEY); // read the local template html file const templatePath = path.join(__dirname, '../../templates/en/account/verifyAccount/index.html'); const htmlContent = fs.readFileSync(templatePath, 'utf-8'); const sendWithLocalFile = { content: [{ type: 'text/html', value: htmlContent }], to: 'chase.wu1990@gmail.com', from: 'chase.wu1990@gmail.com', subject: 'Sending with fs read from local file', dynamicTemplateData: { subject: 'Testing Templates', fullName: "Chase", bucketName: '93f06186-0d7c-4bf0-9ed3-596a7d4aa7af_develop', reasonSuspension: "Explicit contents", facebook_link: "https://www.facebook.com/", instagram_link: "https://www.instagram.com/", youtube_link: "https://www.youtube.com/", linkedin_link: "https://www.linkedin.com/", twitter_link: "https://www.linkedin.com/", email: "test@aladia.io", updateLink: "https://docs.aladia.io", courseThumbnail: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHVfnpm7srBabzA86MrYHqeoF6-xsSSZKXDQ&s", userAvatar: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHVfnpm7srBabzA86MrYHqeoF6-xsSSZKXDQ&s", titleDescription: "Title Description", expirationTime: "2 hours", verificationCode: "321937" }, } sgMail.send(sendWithLocalFile).then((res) => { console.log(res); }).catch((error) => { console.error(error.response.body.errors); });
- send with templates:
API
test the emails
using the activity API to test
But it only could know which html template we have send, but could not read the variables in the template sent by backend team.
using the parsing-email API to test
design the new development flow to deploy and update the email templates
Our current flow
FE part:
- edit in email project dev mode
- build html to templates
- git commit, git push,
git tag
BE part:
4. git pull
5. copy /templates
to backend project
6. commit with the git tag
from FE email project
to BE project
7. BE could git log
to check the last commit code to track the template versions
New flow
And we need a new flow to maintain versions
.
create-templates
https://www.twilio.com/docs/sendgrid/api-reference/transactional-templates-versions/create-a-new-transactional-template-version