0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

blastengineのGo SDKを使ってList-Unsubscribeヘッダーを利用する

Posted at

blastengine(ブラストエンジン)はシンプルに使える開発者向けメールサービスを提供しています。何かと面倒なメール配信をシンプルに、かつ確実に送信先へメールを届けられます。

現在、Go言語向けに、blastengine SDKを開発しています。今回は、バルクメール(一括配信メール)のテンプレート登録や大量のアドレス宛に送信する方法について解説します。

ユーザ登録する

blastengineにユーザ登録します。管理画面に入るためのユーザID、パスワードが手に入るので、ログインします(ユーザIDは後で使います)。

送信元ドメインのSPFを設定する

送信元として利用するドメイン(自分で持っているもの)の設定をします。これは任意のドメイン管理サービスで設定できますが、TXTレコードに以下のSPFを追加します。

txt @ v=spf1 include:spf.besender.jp ~all

APIキーを取得する

ログイン後、管理画面の右上にある設定メニューに移動します。

getting-started-6.jpg

そして設定の中で、APIキーを取得します。

getting-started-5.png

必要な情報について

SDKを使う上で必要なのは、先ほどのAPIキーとユーザIDになります。

SDKのインストール

SDKはblastengineMania/blastengine-go: Blastengine Golang SDKにて公開しています。インストールは go get で行います。

go get github.com/blastengineMania/blastengine-go

初期化

先ほどのAPIキーとユーザIDを使って初期化します。

package main

import (
	"fmt"
	"github.com/blastengineMania/blastengine-go"
)

func main() {
	apiKey := "yourApiKey"
	userId := "yourUserId"
	client := blastengine.Initialize(apiKey, userId)
}

メールの送信

メール送信時のクラス

blastengine Go SDKでメール送信を行う際には、2つのクラスが利用できます。

  • Transaction:
    都度配信用クラス
  • Bulk:
    一括配信用クラス

以下のメソッド名は共通です。

List-Unsubscribe用の情報設定

List-Unsubscribeヘッダーを使う際には、 SetListUnsubscribe メソッドを使います。

transaction := client.NewTransaction()
transaction.SetListUnsubscribe(&ListUnsubscribeParams{
  Email: "unsubscribe+__code__@example.com",
})

bulk := client.NewBulk()
bulk.SetListUnsubscribe(&ListUnsubscribeParams{
  Url: "https://example.com/unsubscribe/__code__",
})

SetListUnsubscribeUrlEmail をオプションに取ります。どちらもオプションです。__code__ は置換文字列になります。

メールの送信

メールの送信は Send メソッドを使います。

err = bulk.Send(nil) // または transaction.Send()
if err != nil {
  t.Errorf("Expected error to be nil, but got %v", err)
}

まとめ

List-Unsubscribeヘッダーは、Gmailのガイドライン変更に伴って、対応が必須になっている機能になります。blastengineの場合は、APIとSMTP両方でList-Unsubscribeヘッダーに対応しています。

現在はGmailのみですが、他のメールプロバイダーについても対応が進んでいくことでしょう。blastengineを使って、配信したメールを確実に受信者に届けるためにも、List-Unsubscribeヘッダーの対応を行ってください。

blastengine API

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?