我希望能够通过以下方式向多个电子邮件地址发送电子邮件:
my $email = Email::Simple->create(
header => [
To => '"My Name" <myname@something.com>',
From => '"Someone1" <some@somewhere.com>',
Subject => $subject,
],
body => $body
);
sendmail($email, {transport => $transport});
是否可以写:
From => '"Someone1" <some@somewhere.com>', '"Someone2" <some2@somewhere.com>'
答案 0 :(得分:12)
只需在字符串中使用逗号:
my $email = Email::Simple->create(
header => [
To => join(", ", @people),
From => '"Someone1"',
Subject => $subject,
],
body => $body
);
答案 1 :(得分:1)
如果您要将邮件发送到多个邮件地址,则密钥为TO
而不是FROM
所以,你可能会使用类似的东西:
To => 'mail1@mail.com;mail2@mail.com;mail3@mail.com;mail4@mail.com'
答案 2 :(得分:-1)
将所有电子邮件放入数组中,然后使用foreach遍历数组:
#!/usr/bin/perl -w
use strict;
use Email::Send;
use Email::Send::Gmail;
use Email::Simple::Creator;
my @emails = ('foo@bar.com', 'bar@foo.com', 'etc@foo.com');
my $num = @emails;
foreach (@emails) {
my $email = Email::Simple->create(
header => [
From => 'FROM@gmail.com',
To => "$_",
Subject => "$subject",
],
body => "$body"
);
my $sender = Email::Send->new(
{ mailer => 'Gmail',
mailer_args => [
username => 'FROM@gmail.com',
password => 'PASSWORD',
]
}
);
eval { $sender->send($email) };
}
注意:这适用于您决定使用的模块。我在这里使用过:Email :: Send(:: Gmail)和Email :: Simple :: Creator。