adt/mailer

Nette 邮件解决方案的终极选择。

v3.2 2023-05-28 05:54 UTC

README

使用 adt/mail-api

  1. 为所有项目使用单个邮件服务,
  2. 确保更高的邮件送达率。

安装

composer

composer require adt/mailer

config.neon

extensions:
	adtMailer: ADT\Mailer\DI\AdtMailerExtension

adtMailer:
	remote:
		api: yourAdtMailApiInstance.com:1234

		# can be either static string or method, required
		key: yourPrivateKey

	error:
		# mode: silent => log and continue
		# mode: exception => throw 
		mode: silent

		# all undelivered messages are stored here (applies to mode: silent)
		logDir: %logDir%/adt_mailer

	# if recipient is suppressed, this address receives notification and delist link
	# can be either an email address, url or a callback returning an email address or url
	suppressionControlAddress: @App\Model\SuppressionControl::decide

使用方法

// inject IMailer into $this->mailer

// create message
$message = new \Nette\Mail\Message;

// send message
$this->mailer->send($message);

“内部”发生了什么?

  1. 连接到 adt/mail-api 服务器。
  2. 消息被序列化并发送到那里。
  3. 如果连接/传输失败,下一步由 error.mode 配置决定
  • silent: 将邮件存储到 error.logDir,使用 Tracy 记录日志,并继续执行;
  • exception: 不进行任何日志记录,直接抛出异常。