通过firebase云功能发送电子邮件

时间:2018-06-05 13:35:32

标签: javascript firebase google-bigquery google-cloud-functions

我有一个包含用户电子邮件的大查询表,我想向他们发送一封时事通讯电子邮件(表格中大约500行) 当该功能运行时,它仅在超时后向30-35个用户发送电子邮件,如果我将列表减少到100,则会在一个电子邮件ID上多次发送电子邮件 以下是我的代码 - :  bigQuery.query({

         exports.date = functions.https.onRequest((req, res) => {
     const bigQuery = bigquery({ projectId: 'littleone-150007' });
       var someVar = [];
        var someVar1 =[];

       bigQuery.query({
   query:`Select email from table`
   useLegacySql: false
 }).then(function (rows) {
  setValue(rows);
  });
  function setValue(value) {
  someVar = value;

   //console.log(someVar); // data is printing here

   var someVar = value[0].map(function(o) { return o.email; });

//console.log(someVar); 

var i,datalength;
datalength = someVar.length;

 var emailsubj=`subject`;
 var emailbody=`newsleter body`
 for(i=0;i<datalength;i++){
     //console.log(someVar[i])
      const mailOptions = {
       from: `Madhu from Mylo <noreply@firebase.com>`,
       to: someVar[i],
       bcc: `qa@myloapp.in`
       }
       mailOptions.subject = emailsubj ;
       mailOptions.html = emailbody;
       mailTransport.sendMail(mailOptions).then(() => {
        console.log('Uninstall mail sent :', someVar[i]);

       });
       }

我需要更改以便只有一封邮件会发送给用户。??

1 个答案:

答案 0 :(得分:1)

如果您这样存储电子邮件:

var someVar = ['someemail@mail.com', 'another@mail.com'];

您可以执行以下操作:

var someVar = ['client@mail.com', 'another@mail.com'];
var sendTo = someVar.join(','); 
var mailOptions = {
  from: 'truironusa@gmail.com', // sender address
  to: sendTo, // list of receivers
  subject: 'My newsletter', // Subject line
  html: '<b>content</b>', // html body
  // plain: 'Some text' // plain text
};