简体   繁体   English

如何使用Email :: Send :: SMTP :: Gmail将电子邮件发送给多个收件人

[英]How to send an email to more than one recepient using Email::Send::SMTP::Gmail

I am trying to write a simple perl script for sending emails using Email::Send::SMTP::Gmail. 我正在尝试编写一个简单的perl脚本,以使用Email :: Send :: SMTP :: Gmail发送电子邮件。

Following is the script that I have written so far. 以下是我到目前为止编写的脚本。

   use strict;
   use warnings;

   use Email::Send::SMTP::Gmail;

   my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
                                       -login=>'abc@gmail.com',
                                       -pass=>'12345',
                   -port=>587,
                   -verbose=>1,
                   -debug=>1);

   $mail->send(-to=>'pqr@gmail.com', -subject=>'Hello!',     -body=>'Just testing it', -verbose=>1, -debug=>1);

   $mail->bye;

This script works fine. 这个脚本工作正常。 How can I send this email to more than one person( ie more than one email id in the "to" field). 如何将这封电子邮件发送给多个人(即,“收件人”字段中有多个电子邮件ID)。 I have tried using: 我尝试使用:

$mail->send(-to=>['pqr@gmail.com', 'xyz@gmail.com'], -subject=>'Hello!',     -body=>'Just testing it', -verbose=>1, -debug=>1);

But I get an error: 但是我得到一个错误:

Net::SMTPS=GLOB(0x23b77a8)>>> RCPT TO:<ARRAY(0x1ee5e78)>
Net::SMTPS=GLOB(0x23b77a8)<<< 553 5.1.2 The address specified is not a  valid RFC-5321 address. w78sm722980qka.25 - gsmtp

From the documentation : put commas between the email addresses. 文档中 :在电子邮件地址之间添加逗号。

send(-to=>'', [-subject=>'', -cc=>'', -bcc=>'', -replyto=>'', -body=>'', -attachments=>'']) send(-to =>'',[-subject =>'',-cc =>'',-bcc =>'',-replyto =>'',-body =>'',-attachments =>' “])
It composes and sends the email in one shot 一键撰写并发送电子邮件

to, cc, bcc: comma separated email addresses 到,抄送,密件抄送: 逗号分隔的电子邮件地址
attachments: comma separated files with full path 附件:逗号分隔的完整路径文件

$mail->send(-to=>'a@gmail.com,b@gmail.com,c@gmail.com,...'

简单地将所有收件人添加为以逗号分隔的列表:

(-to=>'pqr@gmail.com,rec2@gmail.com' ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM