相关疑难解决方法(0)

无法通过nodejs中的google api发送邮件

我正在尝试通过Google API发送电子邮件.

我在node.js中使用googleapis进行Google API访问.

我的问题是,当我尝试发送没有附件的简单邮件时,我收到以下错误:

'raw'RFC822有效负载消息字符串或通过/ upload/*URL上传消息

我没有在我的请求中定义有附件,我没有在电子邮件地址中看到任何错误.

请帮忙.

我的代码:

    var google = require('googleapis');
    var gmailClass = google.gmail('v1');

    var email_lines = [];

    email_lines.push("From: \"Some Name Here\" <rootyadaim@gmail.com>");
    email_lines.push("To: hanochg@gmail.com");
    email_lines.push('Content-type: text/html;charset=iso-8859-1');
    email_lines.push('MIME-Version: 1.0');
    email_lines.push("Subject: New future subject here");
    email_lines.push("");
    email_lines.push("And the body text goes here");
    email_lines.push("<b>And the bold text goes here</b>");

    var email =email_lines.join("\r\n").trim();

    var base64EncodedEmail = new Buffer(email).toString('base64');

    gmailClass.users.messages.send({
        auth: OAuth2Client,
        userId: "me",
        message: 
        {
             raw: base64EncodedEmail
        }           
      },
    function(err, results){});
Run Code Online (Sandbox Code Playgroud)

javascript google-api node.js google-api-nodejs-client

13
推荐指数
1
解决办法
3470
查看次数

使用javascript通过谷歌api发送邮件失败

我正在尝试使用JavaScript通过Google API发送电子邮件.

我的问题是,当我尝试发送没有附件的简单邮件时,我收到以下错误:

'raw'RFC822有效负载消息字符串或上传消息via/upload/*URL required`

我的代码

function sendMessage() {
gapi.client.load('gmail', 'v1', function() {
    // Web-safe base64 
    var to = 'someone@someone.nl',
        subject = 'Hello World',
        content = 'send a Gmail.'

    var base64EncodedEmail = btoa(
          "Content-Type:  text/plain; charset=\"UTF-8\"\n" +
          "Content-length: 5000\n" +
          "Content-Transfer-Encoding: message/rfc2822\n" +
          "to: someone@someone.nl\n" +
          "from: \"test\" <test@gmail.com>\n" +
          "subject: Hello world\n\n" +

          "The actual message text goes here"
            ).replace(/\+/g, '-').replace(/\//g, '_');

    var mail= base64EncodedEmail;
    console.log(mail);
    var request = gapi.client.gmail.users.messages.send({
      'userId': "me",
      'message': {
          'raw': mail
        }
    });
    request.execute(function(response){ …
Run Code Online (Sandbox Code Playgroud)

javascript email google-api google-api-client

7
推荐指数
1
解决办法
3278
查看次数

使用Google API仅使用访问令牌发送电子邮件

我想通过Google API发送电子邮件,而不需要不必要的OAUTH2参数.我只有该用户的access_token和refresh_token.

如何使用Request npm插件通过NodeJS中的基本POST请求通过Gmail API发送电子邮件?

google-api node.js google-api-nodejs-client gmail-api

4
推荐指数
1
解决办法
3499
查看次数