Skip to content
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
855be69
Added pull request template
RajeshGovo Jan 11, 2022
4c31422
updated header
RajeshGovo Jan 11, 2022
7e17e6b
Update pull_request_template.md
sqrrrl Jan 11, 2022
9f55a91
Update pull_request_template.md
sqrrrl Jan 11, 2022
74d534f
Add unit/integration test to checklist
sqrrrl Jan 11, 2022
de572d9
Merge branch 'googleworkspace:master' into master
RajeshGovo Jan 12, 2022
0472431
Gmail snippets original code from devral repo.
anuraggoogler Jan 17, 2022
5aa14bf
Gmail snippets original code from devral repo.
anuraggoogler Jan 17, 2022
553434b
Merge pull request #6 from anuraggoogler/master
RajeshGovo Jan 18, 2022
955e3c0
Merge branch 'googleworkspace:master' into master
anuraggoogler Jan 19, 2022
f8af620
Create and send an email message with and without attachment
anuraggoogler Jan 19, 2022
24544ac
Merge branch 'googleworkspace:master' into master
RajeshGovo Jan 20, 2022
292d1cb
Update send_message.py
anuraggoogler Jan 20, 2022
38643ca
Update send_message_with_attachment.py
anuraggoogler Jan 20, 2022
a899d67
Update send_message.py
anuraggoogler Jan 20, 2022
2b63293
Merge branch 'googleworkspace:master' into master
anuraggoogler Jan 21, 2022
523897e
Merge pull request #13 from anuraggoogler/gmail-patch-3
anuraggoogler Jan 21, 2022
e189799
Delete send_message.py
anuraggoogler Jan 24, 2022
6fefd5b
Delete send_message_with_attachment.py
anuraggoogler Jan 24, 2022
6e00c31
Create and update signature in gmail
anuraggoogler Jan 25, 2022
c516101
Merge pull request #21 from anuraggoogler/gmail-patch-3
RajeshGovo Jan 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions gmail/snippet/settings snippets/update_signature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Copyright 2018 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# [START gmail_update_signature]

from __future__ import print_function

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def update_signature():
"""Create and update signature in gmail.
Returns:Draft object, including updated signature.

Load pre-authorized user credentials from the environment.
TODO(developer) - See https://developers.google.com/identity
for guides on implementing OAuth2 for the application.
"""
creds, _ = google.auth.default()

try:
# create gmail api client
service = build('gmail', 'v1', credentials=creds)

primary_alias = None

# pylint: disable=E1101
aliases = service.users().settings().sendAs().list(userId='me')\
.execute()
for alias in aliases.get('sendAs'):
if alias.get('isPrimary'):
primary_alias = alias
break

send_as_configuration = {
'displayName': primary_alias.get('sendAsEmail'),
'signature': 'Automated Signature'
}

# pylint: disable=E1101
result = service.users().settings().sendAs() \
.patch(userId='me', sendAsEmail=primary_alias.get('sendAsEmail'),
body=send_as_configuration).execute()
print(F'Updated signature for: {result.get("displayName")}')

except HttpError as error:
print(F'An error occurred: {error}')
result = None

return result.get('signature')


if __name__ == '__main__':
update_signature()
# [END gmail_update_signature]