[英]How can I send email to multiple email addresses using Email::Simple in Perl?
I want to be able to send email to multiple email addresses in: 我希望能够将电子邮件发送到以下位置的多个电子邮件地址:
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});
Is it possible to write: 是否可以写:
From => '"Someone1" <some@somewhere.com>', '"Someone2" <some2@somewhere.com>'
Just use commas in the string: 只需在字符串中使用逗号:
my $email = Email::Simple->create(
header => [
To => join(", ", @people),
From => '"Someone1"',
Subject => $subject,
],
body => $body
);
If you want send mail to multiple mail address the key is TO
not FROM
如果要将邮件发送到多个邮件地址,则密钥为
TO
FROM
So, you maybe will be using something like: 因此,您可能会使用类似:
To => 'mail1@mail.com;mail2@mail.com;mail3@mail.com;mail4@mail.com'
Put all of the emails inside of an array, then iterate through the array with a foreach: 将所有电子邮件放入数组中,然后使用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) };
}
Note: This will work for whichever module you decide to use. 注意:这将适用于您决定使用的任何模块。 Here I've used: Email::Send(::Gmail), and Email::Simple::Creator.
在这里,我使用了:Email :: Send(:: Gmail)和Email :: Simple :: Creator。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.