标签: gmail-api

如何在 ASP.NET 中使用具有 HTML 正文 + 附件的 GMAIL API 发送电子邮件

var msg = new AE.Net.Mail.MailMessage
              {
                  Subject = subject,
                  Body = bodyhtml,
                  From = new System.Net.Mail.MailAddress("myemail")

              };
            foreach (string add in vendorEmailList.Split(','))
            {
                if (string.IsNullOrEmpty(add))
                    continue;

                msg.To.Add(new System.Net.Mail.MailAddress(add));
            }

            msg.ReplyTo.Add(msg.From); // Bounces without this!!
            msg.ContentType = "text/html";

            ////attachment code

            foreach (string path in attachments)
            {
                var bytes = File.ReadAllBytes(path);
                string mimeType = MimeMapping.GetMimeMapping(path);
                AE.Net.Mail.Attachment attachment = new AE.Net.Mail.Attachment(bytes, mimeType, Path.GetFileName(path), true);
                msg.Attachments.Add(attachment);
            }
            ////end attachment code

            var msgStr = new StringWriter();
            msg.Save(msgStr);

            Message message = new Message();
            message.Raw = Base64UrlEncode(msgStr.ToString()); …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net gmail-api

2
推荐指数
1
解决办法
4052
查看次数

为什么我在 Users.history:list API 中得到空数组

我正在尝试使用Users:History带有historyId的API来获取gmail帐户中完成的更改历史记录。但不知何故,它会在完成几秒钟或几分钟的更改后返回数据。

代码

function listHistory($service, $userId, $startHistoryId) {
  $opt_param = array('startHistoryId' => $startHistoryId);
  $pageToken = NULL;
  $histories = array();

  do {
    try {
      if ($pageToken) {
        $opt_param['pageToken'] = $pageToken;
      }
      $historyResponse = $service->users_history->listUsersHistory($userId, $opt_param);
      if ($historyResponse->getHistory()) {
        $histories = array_merge($histories, $historyResponse->getHistory());
        $pageToken = $historyResponse->getNextPageToken();
      }
    } catch (Exception $e) {
      print 'An error occurred: ' . $e->getMessage();
    }
  } while ($pageToken);


  return $histories;
}
Run Code Online (Sandbox Code Playgroud)

参考: https: //developers.google.com/gmail/api/v1/reference/users/history/list

php gmail-api

2
推荐指数
1
解决办法
958
查看次数

Gmail API-元数据范围不支持“q”参数

我正在尝试为我的网络应用程序使用 Gmail API。我想要的是获取带有附件文件的消息,并且我正在遵循本教程

问题是当我使用“q”参数时,它返回错误:Metadata scope does not support 'q' parameter

我的请求网址

注:我的授权范围是:

api metadata google-api google-apis-explorer gmail-api

2
推荐指数
1
解决办法
4183
查看次数

如何在 Node.JS 中使用 gmail API 创建带有附件的草稿消息?

我正在使用Gmail API,需要使用附件创建新草稿,我正在遵循官方文档:https://developers.google.com/gmail/api/v1/reference/users/drafts/create


    let response2 = await gmail.users.drafts.create({
        'userId': 'me',
        'resource': {
            'message': {
                'raw': payload
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

此代码段在 Gmail 中创建草稿邮件,但无法从我的本地计算机附加该文件

enter code here我可以在哪里从本地找到附加文件的partId和零件数组

有效负载参考:https://www.any-api.com/googleapis_com/gmail/docs/Definitions/MessagePart

    let response2 = await gmail.users.drafts.create({
        'userId': 'me',
        'resource': {
            'message': {
                'raw': payload
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

javascript google-api node.js gmail-api

2
推荐指数
1
解决办法
1627
查看次数

GmailAPI:“向 Cloud PubSub 项目/[project-id]/topics/[topic-id] 发送测试消息时出错:用户无权执行此操作。”?

我正在使用 Gmail API,并尝试使用 Python 3.9 设置推送通知。当我尝试在 Gmail 收件箱上调用 watch() 时,出现错误,即使我已遵循针对类似问题给出的所有建议。错误如下:

"Error sending test message to Cloud PubSub projects/[project-id]/topics/[topic-id] : User not authorized to perform this action."


到目前为止,我已经做了以下事情:

  • 创建主题
  • 创建订阅
  • 手动发送和接收消息
  • 创建一个服务帐户,具有“所有者”和“Cloud Pub/Sub 服务代理”权限
  • 对于该主题,将服务帐户设置为所有者
  • 对于订阅,将服务帐户设置为所有者

就代码而言,我只是添加到Google 提供的Python Quickstart 文件( https://developers.google.com/gmail/api/quickstart/python )中。这是我添加的内容:

from __future__ import print_function
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']

def main():
    """Shows basic …
Run Code Online (Sandbox Code Playgroud)

python gmail push-notification gmail-api google-cloud-pubsub

2
推荐指数
1
解决办法
723
查看次数

使用gmail-api和google-api-php-client发送电子邮件

我正在使用https://github.com/google/google-api-php-client,我想发送一封包含用户授权的Gmail帐户的测试电子邮件.

这是我到目前为止:

$msg = new Google_Service_Gmail_Message();  
$msg->setRaw('gp1');  
$service->users_messages->send('me', $msg);  
Run Code Online (Sandbox Code Playgroud)

这导致退回电子邮件,因为我不知道如何设置原始邮件.我在经过身份验证的用户的收件箱中看到了反弹.我想学习如何设置电子邮件的"收件人","抄送","密件抄送","主题"和"正文"的值.我相信我还需要对原始数据进行64位编码.我可能想在我的电子邮件正文中使用一些HTML.

请帮助提供使用gmail-api和google-api-php-client发送电子邮件的工作示例.

以下是收件箱中的退回电子邮件:

Bounce -nobody@gmail.com- 12:58 PM(7分钟前)
给我
发生错误.您的邮件未发送.

,日期:星期四,2014年7月24日10:58:30 -0700消息ID:CABbXiyXhRBzzuaY82i9iODEiwxEJWO1 = jCcDM_TH-

google-api-php-client gmail-api

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

使用Gmail API发送电子邮件时出错?

我正在尝试使用Gmail java API发送邮件.我得到以下错误.

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Insufficient Permission",
    "reason" : "insufficientPermissions"
  } ],
  "message" : "Insufficient Permission"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:314)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1060)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
    at GMailLibrary.SendEmail.sendMessage(SendEmail.java:32)
    at GMailLibrary.GMailAuthentication.main(GMailAuthentication.java:85)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)

我使用身份验证代码完成了身份验证部分.以下是我发送电子邮件的代码.

public class SendEmail 
{
      public static void sendMessage(Gmail service, String userId, MimeMessage email)throws MessagingException, IOException 
      {
            Message message = createMessageWithEmail(email);
            message …
Run Code Online (Sandbox Code Playgroud)

java sendmail gmail-api

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

Gmail API仅读取元数据范围

我使用服务帐户和域范围授权访问客户域下所有具有只读范围的电子邮件帐户https://www.googleapis.com/auth/gmail.readonly 在邮件获取请求中,我使用格式选项"metadata" with fields ='payload/headers',仅返回电子邮件标题,但不返回邮件内容.

有没有办法限制我的应用程序访问元数据而不限制电子邮件的内容?这将确保我的应用程序无法读取敏感的电子邮件内容信息并且只能访问元数据.

谢谢!

oauth-2.0 google-oauth gmail-api

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

python 3.6 gmail API?发送带有附件的电子邮件

该python 3脚本假设用于创建电子邮件,将单个文件(使用其url)附加到该电子邮件并发送。它发送了电子邮件,但是create_message_with_attachment()

TypeError:附加内容在非分段有效载荷的邮件上无效

我确实阅读了Google文档。谈论它的堆栈线程专注于精美的附件样式,同时在其顶部混合了python版本的不同语法。

下面的代码是几个来源的拼凑而成。我努力使他们一起参加create_message_with_attachment()

例如,我不知道是否应包含此代码(来自于此代码的create_message_without_attachment()。底部的Cf)

raw = base64.urlsafe_b64encode(msg.as_bytes())
raw = raw.decode()
body = {'raw': raw}
return body
Run Code Online (Sandbox Code Playgroud)

带有附件代码的创建消息:

import httplib2
import os
import oauth2client
from oauth2client import client, tools
import base64
from email import encoders

#needed for attachment
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

#needed for gmail service
from apiclient import errors, discovery  

#The scope URL for read/write access to the gmail api 
SCOPES = 'https://www.googleapis.com/auth/gmail.send'

CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Gmail API Python …
Run Code Online (Sandbox Code Playgroud)

python email email-attachments python-3.x gmail-api

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

Gmail API附件Base64url解码

我目前正试图来存储所有的Gmail电子邮件attachement,巫婆在base64url(编码https://developers.google.com/gmail/api/v1/reference/users/messages/attachments)。

gmail.users.messages.attachments.get({
    'auth': auth,
    'userId': 'me',
    'id': 'attachementId',
    "messageId": 'messageId'
}, function(err, response, seg) {
    if (err) {
       //
    } else {
        var base64_attachement = response.data.replace(/-/g, '+').replace(/_/g, '/').replace(/ /g, '+');
        var buffer = new Buffer(base64_attachement, "base64");
        var attachementDecode = buffer.toString();
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,当我将消息存储在文件中或S3中,并尝试以良好的格式读取消息时,我什么也看不到,图像编辑器的gimp表示图像已损坏。我究竟做错了什么 ?我真的丢了,我怎么能在解码格式base64url谷歌的attachement?

javascript gmail base64 node.js gmail-api

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