Python-SendMail: Small python script that uses Google OAuth 2.0 authentication for sending email with your google account

SendMail

Small python script that uses Google OAuth 2.0 authentication for sending email with your google account

#Requirements

  • Python 3.4
  • google-api-python-client-py3 1.2
  • httplib2 0.9

The best way for testing this is to create virtualenv

virtualenv SendMail
source SendMail/bin/activate
pip install google-api-python-client-py3
python3 ./path/to/SendMail.py

#Usage First create an application through Google API Console for obtaining the CLIENT_SECRET and CLIENT_ID to be used inside the script. After that you've to setup the oauth 2.0 credentials by typing

sudo ./SendMail --setup

Finally you can start sending email by invoking

sudo ./SendMail \
--from 'from_email' \
--to 'to_email' \
--subject 'subject' \
--body 'body'

Comments

  • I got such error:An error occurred: 'NoneType' object has no attribute 'encode'
    I got such error:An error occurred: 'NoneType' object has no attribute 'encode'

    Mar 5, 2019

    [[email protected] SendMail]# python3 SendMail.py --setup Authenticate here: https://accounts.google.com/o/oauth2/auth?client_id=d61eed4ut1.apps.gododtent.dcom&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.compose&access_type=offline&response_type=code Please paste the obtained code: 4/Bd345345345345JBGmAFzHSvaiSWZrnN2H8PaBwUBZsFH3A An error occurred: 'NoneType' object has no attribute 'encode'

    Reply