如何使用 mailgun 发送 batch/mass 封带附件的邮件?
How to send batch/mass emails with attachments using mailgun?
我想批量发送带附件的邮件。我可以通过将相同的文件附加到所有电子邮件来发送批量电子邮件。但是我需要通过在收件人变量中添加文件路径来将不同的文件附加到不同的电子邮件。我在 mailgun 的官方文档中看不到任何相关内容。
这是我的代码:
# Instantiate the client.
$mgClient = new Mailgun('key-****');
$domain = "foo.bar.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'gido@foo.baar.com',
'to' => array('user1@gmail.com', 'user2@gmail.com'),
'subject' => 'Hi %recipient.first%',
'text' => 'Hey there, Just Testing',
'recipient-variables' => '{"user1@gmail.com": {"first":"User1", "id":1, "file" : "/path/to/file1"},
"user2@gmail.com": {"first":"User2", "id": 2, "file" : "/path/to/file2"}}'
), array(
'attachment' => array('%recipient.file%')
));
以上代码无效。附件数组无法使用收件人变量。将 %recipient.image%
替换为 /path/to/file
效果很好。
来自doc:
'attachment' => [['fileContent'=>$binaryFile,'filename'=>'test.jpg']]
或
'attachment' => [['filePath'=>'/tmp/foo.jpg','filename'=>'test.jpg']]
或(内联):
'inline' => [['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg']]
根据与 Mailgun 支持团队的对话,目前 Mailgun 无法为每个收件人分配特定的附件。可以尝试的一件事是在服务器上提供文件并为用户分配 URL 以从中检索文件(仅在文件不机密且永久存储在服务器上时才建议这样做。)。
我想批量发送带附件的邮件。我可以通过将相同的文件附加到所有电子邮件来发送批量电子邮件。但是我需要通过在收件人变量中添加文件路径来将不同的文件附加到不同的电子邮件。我在 mailgun 的官方文档中看不到任何相关内容。
这是我的代码:
# Instantiate the client.
$mgClient = new Mailgun('key-****');
$domain = "foo.bar.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'gido@foo.baar.com',
'to' => array('user1@gmail.com', 'user2@gmail.com'),
'subject' => 'Hi %recipient.first%',
'text' => 'Hey there, Just Testing',
'recipient-variables' => '{"user1@gmail.com": {"first":"User1", "id":1, "file" : "/path/to/file1"},
"user2@gmail.com": {"first":"User2", "id": 2, "file" : "/path/to/file2"}}'
), array(
'attachment' => array('%recipient.file%')
));
以上代码无效。附件数组无法使用收件人变量。将 %recipient.image%
替换为 /path/to/file
效果很好。
来自doc:
'attachment' => [['fileContent'=>$binaryFile,'filename'=>'test.jpg']]
或
'attachment' => [['filePath'=>'/tmp/foo.jpg','filename'=>'test.jpg']]
或(内联):
'inline' => [['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg']]
根据与 Mailgun 支持团队的对话,目前 Mailgun 无法为每个收件人分配特定的附件。可以尝试的一件事是在服务器上提供文件并为用户分配 URL 以从中检索文件(仅在文件不机密且永久存储在服务器上时才建议这样做。)。