Using Any Email Delivery Service for Email Sending from Kuroco(blastengine)
Overview
By using the trigger "Instead of the default email sending method (SendGrid)", you can send notification and invitation emails using any email delivery service such as blastengine, Mailchimp, Amazon SES, etc.
In this tutorial, we will show you how to replace email sending from SendGrid to blastengine.
What you'll learn
You will learn how to implement email sending using any email delivery service with the following steps:
Prerequisites
In this tutorial, we will be using blastengine for email sending. .
Please refer to the blastengine website for detailed information about the service, as well as its API documentation.
Also, since we will be configuring SPF/DKIM, please make sure to use a domain that you own for the "from" email.
Please note that if you do not use SendGrid, you will not be able to use the tracking features (delivery, email bounce, open rate, click count).
Setting up blastengine
First, access blastengine and sign up for a free trial.
Once you have logged in to your trial account, click on "Address Registration" under the "API Integration Trial" tab to enter the address that will allow delivery from blastengine.
Next, obtain the API key.
Click on the "Settings" page to go to the blastengine settings page.
Click on "Check/Reissue" for the API key.
Take note of the API key that is displayed.
Also, access the Account Management page and take note of the ID.
Setting up Kuroco
Registering the secret
Access the Kuroco management screen and In the left sidebar menu, under "SETTINGS", click [Environment] -> [Secrets].
Click on [Add].
Register the API key obtained from the blastengine settings page and the ID as shown below.
Field | Value |
---|---|
Name | BLASTENGINE_API_KEY |
Value | API key of blastengine |
Field | Value |
---|---|
Name | BLASTENGINE_ID |
Value | ID of blastengine |
You have now completed the preparation to use blastengine.
Registering custom processing
Once you have prepared to use blastengine, write the custom processing to replace email sending from SendGrid to blastengine.
In the left sidebar menu, click [Operation] -> [Custom function]
Click on "Add".
Configure as follows:
Item | Value |
---|---|
Title | sending_email_with_blastengine |
Identifier | sending_email_with_blastengine |
Trigger | Instead of the default email sending method (SendGrid) |
Processing | The following content |
{* Create BearerToken *}
{secret var='apiKey' key='BLASTENGINE_API_KEY'}
{secret var='id' key='BLASTENGINE_ID'}
{rcms_hash var='token' data="`$id``$apiKey`" algo="sha256"}
{assign var='BearerToken' value=$token|strtolower|base64_encode}
{* Set Request Headers *}
{append var=headers value="Authorization: Bearer `$BearerToken`"}
{append var=headers value="Content-Type: application/json"}
{append var=headers value="Accept-Language: ja-JP"}
{* Set Body *}
{assign var='body' value=$payload|@json_decode}
{assign var='body.from.email' value="noreply@kuroco-mail.app"}
{* Send Request *}
{api
endpoint="https://app.engn.jp/api/v1/deliveries/transaction"
method='POST'
headers=$headers
body=$body
var=response
status_var=status
}
{logger msg1="blastengine_mail_log" msg2=$body msg3=$response}
{assign var='is_mail_sent' value=true}
Please change noreply@kuroco-mail.app
to your own email address.
Once you have entered the information, click [Add] to add the custom process.
Confirmation of operation
Let's actually send an email from Kuroco. To confirm the operation, we will use the password reminder.
Access the Kuroco login screen and click [Forgot your password?].
Enter the email address that has been allowed to receive emails from blastengine and click [Send].
When you check the received email, you can see that the "from" address is the email address in the custom process and the display of "via besender-s.jp".
Also, when you check the delivery log of blastengine, you can see that the email was sent from blastengine.
Increasing email deliverability
So far, you have been able to send emails using blastengine. To prevent sent emails from being classified as spam, we will set up SPF records and DKIM authentication.
By implementing email authentication, you can prevent email spoofing and verify that the email was actually sent by the domain owner.
As the processing for emails without SPF/DKIM settings becomes stricter year by year, be sure to implement these settings.
Setting up SPF records
Set the following TXT record in the domain management service.
Hostname | Type | Value |
---|---|---|
Blank | TXT | v=spf1 include:spf.besender.jp ~all |
After setting it up, use MxToolbox's SPF Record Check to verify that it is set up correctly.
Setting up DKIM
Next, set up DKIM. First, prepare a pair of public and private keys, and set the private key in blastengine.
Generating private and public keys
Generate the private key using the OpenSSL command-line tool in your local environment. First, open the terminal and check if OpenSSL is available using the following command.
openssl version
If OpenSSL is not installed, please install it separately, especially for Windows.
Next, create a private key with the following command.
openssl genpkey -algorithm RSA -out private_key.pem
The public key can be extracted from the private key using OpenSSL.
Here is the command to do so.
openssl rsa -pubout -in private_key.pem -out public_key.pem
Register with blastengine
Register the created private key with blastengine.
Access the blastengine settings page and click on [Confirm/Change] for DKIM Signer Settings.
The DKIM Signer Settings will be displayed. Click on "New Registration" and set the following:
Field | Value |
---|---|
Selector | kuroco |
Domain | The domain used in the "From" email |
Private Key | The private key starting with -----BEGIN PRIVATE KEY----- that was created earlier |
Once the input is complete, click [Confirm] to register.
Configure DNS
Set the following TXT record in the domain management service:
Hostname | Type | Value |
---|---|---|
kuroco._domainkey | TXT | v=DKIM1; k=rsa; p=The part of the public key without the -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- |
If the length of the VALUE exceeds the maximum number of characters that can be set, you need to split the TXT record and register it separately.
If necessary, please contact your domain management service for assistance.
Once the configuration is complete, use MxToolbox's DKIM Record Lookup to verify that it is set correctly.
Send another email from Kuroco to confirm that the "From" address is now the custom processing email address, and there is no longer a "via besender-s.jp" indication.
With this, the configuration for using any email delivery service is complete.
Related Documents
Support
If you have any other questions, please contact us or check out Our Slack Community.