Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, user=None, password=None, host='smtp.gmail.com', port='587',
smtp_starttls=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()
if smtp_skip_login and user is None:
user = ''
elif user is None:
user = self._find_user_home_path()
self.user, self.useralias = self._make_addr_alias_user(user)
self.soft_email_validation = soft_email_validation
if soft_email_validation and not smtp_skip_login:
validate_email_with_regex(self.user)
self.is_closed = None
self.host = host
self.port = port
self.starttls = smtp_starttls
self.smtp_skip_login = smtp_skip_login
self.debuglevel = smtp_set_debuglevel
self.encoding = encoding
def set_logging(self, log_level=logging.ERROR, file_path_name=None):
"""
This function allows to change the logging backend, either output or file as backend
It also allows to set the logging level (whether to display only critical/error/info/debug.
e.g.
yag = yagmail.SMTP()
yag.set_logging(yagmail.logging.DEBUG) # to see everything
and
yagmail.set_logging(yagmail.logging.DEBUG, 'somelocalfile.log')
lastly, a log_level of None will make sure there is no I/O.
"""
self.log = get_logger(log_level, file_path_name)
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"
def set_logging(self, log_level=logging.ERROR, file_path_name=None):
"""
This function allows to change the logging backend, either output or file as backend
It also allows to set the logging level (whether to display only critical/error/info/debug.
for example::
yag = yagmail.SMTP()
yag.set_logging(yagmail.logging.DEBUG) # to see everything
and::
yagmail.set_logging(yagmail.logging.DEBUG, 'somelocalfile.log')
lastly, a log_level of :py:class:`None` will make sure there is no I/O.
"""
self.log = get_logger(log_level, file_path_name)