วิธีเปลี่ยนอีเมลผู้ส่ง เมื่อส่งอีเมลด้วยGoogle Script

ในการส่งอีเมลด้วย Google Script นั้น ในส่วนอีเมลผู้ส่งจะเป็นอีเมลที่เรารันScript แต่ถ้าเราอยากเปลี่ยนเป็นอีเมลอื่นก็สามารถทำได้นะ วันนี้เราจะมาทำWorkshopนี้กันครับ ไปลุยกันเล้ยยย

// Presented by BrilliantPy ✓ v.1.0.4
/*######################### Editable1 Start #########################*/
let email_subject = 'สรุปการประชุม';
let email_message = 'รายละเอียดสรุปการประชุม BrilliantPy';
let to_email = "prosperpy.live@gmail.com";
/*#########################  Editable1 End  #########################*/

async function customEmailSender(){
  await sendEmailWithAttachment(to_email);
  // await sendEmailWithAttachmentV2(to_email);
}

async function sendEmailWithAttachment(email) {
  return new Promise(function(resolve,reject) { 
    // let file = DriveApp.getFolderById(folderResponsePdfId).getFilesByName(pdf_name_full);
    // if (!file.hasNext()) {
    //   console.error("Could not open file "+pdf_name_full);
    //   return;
    // }
    try {
      MailApp.sendEmail({
        to: email,
        subject: email_subject,
        htmlBody: email_message,
        // attachments: [file.next().getAs(MimeType.PDF)]
      });
      resolve();
      console.log('sendEmailWithAttachment completed')
    } catch(e) {
      reject();
      console.log("sendEmailWithAttachment error with email (" + email + "). " + e);
    }
  });
}

async function sendEmailWithAttachmentV2(email) {
  return new Promise(function(resolve,reject) { 
    // let file = DriveApp.getFolderById(folderResponsePdfId).getFilesByName(pdf_name_full);
    // if (!file.hasNext()) {
    //   console.error("Could not open file "+pdf_name_full);
    //   return;
    // }
    try {
      let aliases = GmailApp.getAliases();
      console.log("aliases:",aliases);
      GmailApp.sendEmail(email, email_subject, email_message, {'from': aliases[0]});
      resolve();
      console.log('sendEmailWithAttachment completed')
    } catch(e) {
      reject();
      console.log("sendEmailWithAttachment error with email (" + email + "). " + e);
    }
  });
}

ใส่ความเห็น

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *