Package: ezmail
ezmaileasily send out emails via python or the cli using python's SMTP module.Getting starteddownload the package using pip:pip install ezmail.envfileThis module uses environment files to handle sensitive info.
Make sure the following values are defined in it:USERNAME=sender@exmaple.com
PASSWORD=<password>
SMTP=<provider's SMTP server>
PORT=<provider's port>See examplesbelowfor popular providers.send from pythonfromezmailimportsend_mail# by default, an env file named `.env` is searched.send_mail(subject="Email sent with Python",recipients=["r1@example.com","John Doe <john@example.com>"],message="Here go the contents of the message.",)send from the clipython -m ezmail -s "Email sent from bash" -r "r1@example.com" "r2@example.com" -m "This is my message."More advanced usesThis module allows adding attachments to the email, as well as reading in the message and / or recipients from a file instead of defining them directly.pythonPython automatically detects the type of data that is passed into the different fields.For example, to read the recipients from a file, simply pass in a Path or file object instead of a list of strings.A file that defines the recipients must have one recipient per line:r1@example.com
John Doe <john@example.com>The message can also be taken from a Path or file object. If the message contents are html, remember to set thehtmlflag to True.To add attachments, pass in a list of Paths or (read-binary) file objects. The type is automatically detected.If an env file with a name different from.envis used, pass it intoenvfileas a Path object or a stringFor example:frompathlibimportPathfromezmailimportsend_mailrecipients_file=Path("path/to/recipients.txt")messages_file=open("path/to/message.html","r")attachments=[Path("path/to/attachment1.csv"),open("path/to/attachment2.jpg","rb"),]envfile=Path("my/.envfile")send_mail(subject="Email sent with Python",recipients=recipients_file,message=messages_file,attachments=attachments,envfile=envfile,html=True,)clipython -m ezmail --helpto see how to call from the command linePossible flags:-sor--subject: the subject of the email (single argument)message:-mor--message: the contents of the email OR-for--file: the file containing the contents of the emailrecipients:-ror--recipients: the recipients of the email (one or more arguments) OR-rfor--recipientsfile: the file containing the addresses of the recipients-aor--attachments: a list of files to attach to the email (one or more arguments)-eor--env: the env file where the credentials are defined (default.env)-Hor--html: (flag) if present, the contents of the message will be sent as html-vor--verbose: set SMTP server debug level to 1, to debug possible connection issuesPopular SMTP serversHere is a brief description of popular SMTP servers.If having trouble setting up the SMTP server, pass inverbose=Trueinto the python method, or the flag-von the cli version.gmailGmail constantly changes the requirements to be able to send out emails through SMTP. It is recommended that you follow aguide.Then, fill in the missing values from the following.envfileUSERNAME=
PASSWORD=
SMTP="smtp.gmail.com"
PORT=465ZohoZoho makes it very simple to send emails through SMTP. Fill in the missing values from the following.envfile and that's it!USERNAME=
PASSWORD=
SMTP="smtp.zoho.com"
PORT=465