我已经研究了两个星期,找不到任何信息可以通过python脚本更改gmail中的用户签名。您对此问题有解决方案吗?
答案 0 :(得分:0)
Gmail设置API的方法允许管理用户签名,您可以在Manage signature
中找到有关他们的信息。您应该注意,此API已弃用,并将在2019年10月16日被关闭。请尽快迁移到Gmail API,以避免破坏您的应用程序。
Gmail API
Manag signature settings指出您应该使用要管理Gmail API中的电子邮件签名,请使用SendAs资源。可以让您设置签名。
Python
我建议您遵循python quick start并尝试对其进行编辑,以与sendAs方法一起使用
from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# If modifying these scopes, delete the file token.json.
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))
# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', [])
if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
if __name__ == '__main__':
main()