Example #1
0
 def login_oauth2(self, oauth2_file):
     self.smtp = smtplib.SMTP(self.host, self.port, **self.kwargs)
     self.smtp.set_debuglevel(self.debuglevel)
     oauth2_info = get_oauth2_info(oauth2_file)
     auth_string = get_oauth_string(self.user, oauth2_info)
     self.smtp.ehlo(oauth2_info["google_client_id"])
     self.smtp.starttls()
     self.smtp.docmd('AUTH', 'XOAUTH2 ' + auth_string)
Example #2
0
 def __init__(
     self,
     user=None,
     password=None,
     host="smtp.gmail.com",
     port=None,
     smtp_starttls=None,
     smtp_ssl=True,
     smtp_set_debuglevel=0,
     smtp_skip_login=False,
     encoding="utf-8",
     oauth2_file=None,
     soft_email_validation=True,
     useralias=None,
     **kwargs
 ):
     self.log = get_logger()
     self.set_logging()
     self.soft_email_validation = soft_email_validation
     if oauth2_file is not None:
         oauth2_info = get_oauth2_info(oauth2_file)
         if user is None:
             user = oauth2_info["email_address"]
     if smtp_skip_login and user is None:
         user = ""
     elif user is None:
         user = find_user_home_path()
     self.user, self.useralias = make_addr_alias_user(user)
     if useralias is not None:
         self.useralias = useralias        
     if soft_email_validation:
         validate_email_with_regex(self.user)
     self.is_closed = None
     self.host = host
     self.port = str(port) if port is not None else "465" if smtp_ssl else "587"
     self.smtp_starttls = smtp_starttls
     self.ssl = smtp_ssl
     self.smtp_skip_login = smtp_skip_login
     self.debuglevel = smtp_set_debuglevel
     self.encoding = encoding
     self.kwargs = kwargs
     self.cache = {}
     self.unsent = []
     self.num_mail_sent = 0
     self.oauth2_file = oauth2_file
     self.credentials = password if oauth2_file is None else oauth2_info
Example #3
0
 def __init__(
     self,
     user=None,
     password=None,
     host="smtp.gmail.com",
     port=None,
     smtp_starttls=None,
     smtp_ssl=True,
     smtp_set_debuglevel=0,
     smtp_skip_login=False,
     encoding="utf-8",
     oauth2_file=None,
     soft_email_validation=True,
     **kwargs
 ):
     self.log = get_logger()
     self.set_logging()
     self.soft_email_validation = soft_email_validation
     if oauth2_file is not None:
         oauth2_info = get_oauth2_info(oauth2_file)
         if user is None:
             user = oauth2_info["email_address"]
     if smtp_skip_login and user is None:
         user = ""
     elif user is None:
         user = find_user_home_path()
     self.user, self.useralias = make_addr_alias_user(user)
     if soft_email_validation:
         validate_email_with_regex(self.user)
     self.is_closed = None
     self.host = host
     self.port = str(port) if port is not None else "465" if smtp_ssl else "587"
     self.smtp_starttls = smtp_starttls
     self.ssl = smtp_ssl
     self.smtp_skip_login = smtp_skip_login
     self.debuglevel = smtp_set_debuglevel
     self.encoding = encoding
     self.kwargs = kwargs
     self.cache = {}
     self.unsent = []
     self.num_mail_sent = 0
     self.oauth2_file = oauth2_file
     self.credentials = password if oauth2_file is None else oauth2_info
Example #4
0
def login_to_gmail():
    get_oauth2_info(settings.GMAIL_CREDENTIALS_PATH)