Closed wasimsandhu closed 1 year ago
The above code snippet will not work. It's also not ideal to have to encrypt / obscure the user's email account password for this one feature. In the interest of time, going to see if I can just use the user's authenticated Google account for this...
See issue here regarding using Google credentials (since entire authentication process is handled by PyDrive): https://github.com/iterative/PyDrive2/issues/179
def send_email(subject, message_body):
"""
Sends email using Google authenticated credentials
"""
try:
credentials = google_auth.load_credentials_from_file(alt_credentials)[0]
service = build("gmail", "v1", credentials=credentials)
message = EmailMessage()
message.set_content(message_body)
message["Subject"] = subject
message["To"] = get_email_notifications_list(as_string=True)
encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
create_message = { "raw": encoded_message }
send_message = (service.users().messages().send(userId="me", body=create_message).execute())
except Exception as error:
traceback.print_exc()
send_message = None
return send_message