| 17 | CLIENT_SECRET_FILE = "client_secret.json" |
| 18 | APPLICATION_NAME = "Gmail API Python Send Email" |
| 19 | def get_credentials(): |
| 20 | home_dir = os.path.expanduser("~") |
| 21 | credential_dir = os.path.join(home_dir, ".credentials") |
| 22 | if not os.path.exists(credential_dir): |
| 23 | os.makedirs(credential_dir) |
| 24 | credential_path = os.path.join(credential_dir, "gmail-python-email-send.json") |
| 25 | store = oauth2client.file.Storage(credential_path) |
| 26 | credentials = store.get() |
| 27 | if not credentials or credentials.invalid: |
| 28 | flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) |
| 29 | flow.user_agent = APPLICATION_NAME |
| 30 | credentials = tools.run_flow(flow, store) |
| 31 | |
| 32 | print("Storing credentials to " + credential_path) |
| 33 | |
| 34 | return credentials |
| 35 | |
| 36 | |
| 37 | def SendMessage(sender, to, subject, msgHtml, msgPlain, attachmentFile=None): |