How to send a mail with an attachment in gmail api using google-api-nodejs-client for nodejs

时间秒杀一切 提交于 2019-12-11 02:59:45

问题


I wish to send an email with an attachment through gmail.

I'm using google-api-nodejs-client for node.js.

My current message sending code is:

var gmailClass = google.gmail('v1');
gmailClass.users.messages.send({
            auth: OAuth2Client,
            userId: 'me',
            resource: {
              raw: base64EncodedEmail
            },
          }
        ,function(err, results)
        {
        if (!err)
        {
          //do something    
        }
        else
        {
          //do something
        }
});

Is there a way to add an attachment to the send function?


回答1:


Your attachment should be in the "raw" base64EncodedEmail you're already using. The format is simply a full email message (e.g. look at "Show Original" in Gmail or any other mail client to see what an email with an attachment looks like). I imagine there are some MIME email message libraries that will be helpful...



来源:https://stackoverflow.com/questions/26324855/how-to-send-a-mail-with-an-attachment-in-gmail-api-using-google-api-nodejs-clien

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!