【问题标题】:using python how to add clickable image as Gmail Signature使用python如何将可点击的图像添加为Gmail签名
【发布时间】:2021-01-01 02:17:33
【问题描述】:

我的要求是使用 python 我们想将图像添加为 gmail 签名。单击图像后,我们希望重定向到视频文件。

我手动尝试过,通过以下步骤成功添加签名:

  1. 打开谷歌文档并上传图片
  2. 为图片添加了超链接
  3. 现在将图像复制到 gmail 签名部分
  4. 单击图像后,它会成功重定向到视频文件。

使用python,我想以动态方式实现这一目标

  1. 我创建了 Google Drive 凭据
  2. 启用 google docs API
  3. 能够读取文档数据
  4. 现在,我卡住了如何添加文本作为签名。

我正在尝试以下方法

SCOPES = ['https://www.googleapis.com/auth/gmail.settings.basic','https://www.googleapis.c om/auth/gmail.labels','https://www.googleapis.com/auth/gmail.send']

creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', SCOPES)

GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
 addresses = GMAIL.users().settings().sendAs().list(userId='me',
fields='sendAs(isPrimary,sendAsEmail)').execute().get('sendAs')

for address in addresses:
  if address.get('isPrimary'):
    break
 rsp = GMAIL.users().settings().sendAs().patch(userId='me',
    sendAsEmail=address['sendAsEmail'], body=DATA).execute()
print("Signature changed to '%s'" % rsp['signature'])

得到的错误是

“代码”:401, "message": "请求缺少所需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据

请提出前进的方向

谢谢 维杰

【问题讨论】:

  • 我觉得你应该回去一点。您使用什么库来自动化/发送电子邮件?根据您的描述,签名只不过是<img> 标记与@ 987654323@ 在html 中。绝对更容易从 html 源设置签名
  • 通过 html 标签添加是个好主意。目前没有使用任何库。你能推荐一些使用 javascript 或 python 的库来添加图像作为 gmail 签名
  • 它是 Google Apps 的一部分,您想更改所有用户的签名还是只是寻找您自己的签名?
  • 它不是 Google 应用程序的一部分,我们正在尝试使用 python 来处理这个问题
  • 我更新了代码,你能告诉我如何推进它

标签: python oauth-2.0 gmail


【解决方案1】:

终于明白了

SCOPES = 'https://www.googleapis.com/auth/gmail.settings.basic'
store = file.Storage('credentials.json')
creds =None
args.noauth_local_webserver = True

if not creds or creds.invalid:

  flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
  creds = tools.run_flow(flow, store,args)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))

addresses = GMAIL.users().settings().sendAs().list(userId='me',
    fields='sendAs(isPrimary,sendAsEmail)').execute().get('sendAs')
for address in addresses:
  if address.get('isPrimary'):
    break
signature = {'signature':'<img src="http://myserver/mycard.JPG" alt="Trulli" 
  width="200" height="200">'}
 rsp = GMAIL.users().settings().sendAs().patch(userId='me',
    sendAsEmail=address['sendAsEmail'], body=signature).execute()
 print("Signature changed to '%s'" % rsp['signature'])

【讨论】:

    猜你喜欢
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 2017-04-01
    • 2017-12-21
    • 2012-05-08
    • 2017-06-22
    相关资源
    最近更新 更多