GMail将图片直接添加到电子邮件中

时间:2019-07-03 15:04:16

标签: google-apps-script gmail email-attachments

关于此脚本,我可以在电子邮件上附加图片:

function myTesteMail() {
  var file = DriveApp.getFileById('1DyNggP_DAZEO32kSdQTZFiEYG1bPCP3o');
  MailApp.sendEmail('xxxxxx@yyyyyy.com', 'Attachment example', 'my own test.', {name: 'my Script', attachments: [file.getAs(MimeType.JPEG)]});
}

如何在电子邮件中直接添加picutre?

有可能吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用htmlBody中的MailApp.sendMail参数在电子邮件中直接添加图片。您可以看到documentation for MailApp here

function myTesteMail(){

    var email = 'user@domain.ext';
    var subject = 'Subject Test';
    MailApp.sendEmail(email, subject, "", { 
      htmlBody: " <html>\
        <body> Look at this email body \
        <img src='https://www.domain.ext/image.jpg' border='0' alt='error' 
          align='middle'></th>\
        </body>\
        </html>"
    });
}