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?

More than 1 year has passed since last update.

blastengineでメールを時間指定して送信する

Posted at

一般的にメールは即時送信されるものですが、メールマガジンやマーケティング系のメールは時間を指定して送られます。Gmailでも、日時を指定して送信する機能があります。

blastengineでも、同様に日時を指定して送信する機能があります。各SDK毎に、実装方法を紹介します。

JavaScript SDKの場合

JavaScript SDKを使ってメール送信日時を指定する場合は、以下のようにします。

import { BlastEngine, Mail } from 'blastengine';
new BlastEngine('USER_ID', 'API_KEY');
const mail = new Mail;
mail
	.setFrom('admin@example.com', 'Admin')
	.setSubject('Test subject')
	.addTo('user@example.jp')
	.setText('メールの本文');
await mail.send(new Date("2024-05-10 12:00:00")); // 2024年5月10日12時に送信

PHP SDKの場合

PHP SDKを使ってメール送信日時を指定する場合は、以下のようにします。

use Blastengine\Client;
Blastengine\Client::initialize('USER_ID', 'API_KEY');

$mail = new Blastengine\Mail();
$mail
	->to('user@example.jp', array("name1" => "Test"))
	->from('admin@example.com')
	->subject('Test subject')
	->text_part('This is test email to __name1__');
$mail->send(new DateTime("2024-05-10 12:00:00")); // 2024年5月10日12時に送信

Ruby SDKの場合

Ruby SDKを使ってメール送信日時を指定する場合は、以下のようにします。

require 'blastengine'
Blastengine.initialize api_key: 'API_KEY', user_name: 'USER_ID'
mail = Blastengine::Mail.new
mail.from email: 'admin@example.com', name: 'Admin'
mail.addTo email: 'user@example.jp', insert_code: { name1: "name 1" }
mail.subject = "Test email"
mail.text_part = "This is a test email __name1__"
mail.html_part = "<html><body>This is a test email __name1__</body></html>"
mail.send Time.new(2024, 5, 10, 12, 0, 0) # 2024年5月10日12時に送信

Python SDKの場合

Python SDKを使ってメール送信日時を指定する場合は、以下のようにします。

client = Blastengine("USER_ID", "API_KEY")
mail = Mail()
mail.subject('メールの件名')
mail.text_part('テキスト本文 __name__')
mail.from_address("admin@example.com", "Admin")
mail.to('user@example.jp', {'name': 'name 2', 'hash': 'bbbbb'})
mail.send(datetime.datetime(2024, 5, 10, 12, 0, 0)) # 2024年5月10日12時に送信

Java SDKの場合

Java SDKを使ってメール送信日時を指定する場合は、以下のようにします。

BEClient.initialize("USER_ID", "API_KEY");
BEMail mail = new BEMail();
mail.subject ="Test mail from blastengine";
mail.text = "Mail body";
mail.html = "<h1>Hello, from blastengine</h1>";
BEMailAddress fromAddress = new BEMailAddress("admin@example.com", "Admin");
mail.setFrom(fromAddress);
mail.addTo("user@example.jp");
try {
	mail.send(new Date(2024, 5, 10, 12, 0, 0)); // 2024年5月10日12時に送信
} catch (BEError e) {
}

Google Apps Script SDKの場合

Google Apps Script SDKを使ってメール送信をキャンセルするには、以下のようにします。

new BlastEngine('API_USER', 'API_KEY');
const mail = new Mail;
mail
	.setSubject('テストメール')
	.setText('本文 __name1__')
	.setFrom('admin@example.com')
	.addAttachment(Utilities.newBlob('Hire me!', 'text/plain', 'resume.txt'))
	.addTo('user@example.jp', {name1: 'Atsushi'});
mail.send(new Date("2024-05-10 12:00")); // 2024年5月10日12時に送信

使い方

使い方としては、各SDKともにMailクラスを利用します。そして、 send メソッドの引数に送信日時を指定します。そうすると、メールがバルクオブジェクトになり、送信時のステータスが RESERVE になります。後は指定日時になれば、メールが自動的に送信されます。

まとめ

blastengineを使えば、メール送信日時を指定してメールを送信できます。これにより、メールマガジンやマーケティングメールの配信を効率化できます。ぜひお試しください。

エンジニア向けメール配信システム「ブラストエンジン(blastengine)」

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?