Many fixes and docstrings

This commit is contained in:
Antonio de la Rosa 2022-04-01 01:04:29 +02:00
parent eb93be38ea
commit dd67eafd0d
5 changed files with 118 additions and 10 deletions

View file

@ -13,6 +13,8 @@ import ssl as ssl_module
import sys
class SendMail:
"""Class for send email
"""
port=587
@ -25,6 +27,20 @@ class SendMail:
#ssl=True
def __init__(self, ssl=True):
"""Class for send email
Class for send email using standard python library
Attributes:
port (int): The port used for send email, by default 587
host (str): The hostname of mail server used for send the email
username (str): The username for login in mail server
password (str): The password for login in mail server
smtp (smtplib.SMTP): The python SMTP object used for send emails
txt_error: (str): If error, is saved in this attribute
"""
self.smtp=None #smtplib.SMTP(host=self.host, port=self.port)
self.txt_error=''
@ -94,6 +110,18 @@ class SendMail:
return True
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
""" Method that send email
With this method you can send email to multiple address, html, and add attachments to email
Args:
from_adress (str): The adress used for send the email
to_address (list): A list of emails where the email will be sended.
subject (str): The subject of the email
message (str): The content of the message
content_type (str): The type of mail content, can be plain or html.
attatchments (list): A list with a serie of file paths for attach to the email.
"""
if self.smtp==None:
if not self.connect():
@ -174,12 +202,14 @@ class SendMail:
return True
def quit(self):
"""Function used when you need quit connection for any reason"""
if self.smtp!=None:
self.smtp.quit()
self.smtp=None
def __del__(self):
"""Method for clean the connection when the object is closed"""
if self.smtp!=None: