Table of Contents
Mail Sender Module is a python module that helps you send your emails perfectly.
it also supports send mails with attachments.
- using python pip
pip install python-mail-sender
Just do the following steps:
- define
SENDER_ADDR&SENDER_PASS&SMTP_PORT&SMTP_SERVERenv variables- Using python:
import os os.environ["SENDER_ADDR"] = "sender_address" os.environ["SENDER_PASS"] = "sender_pass" os.environ["SMTP_PORT"] = "smtp_port" os.environ["SMTP_SERVER"] = "smtp_server"
- Or using the os terminal.
- Or using the venv activate file:
- depending on the os open the corresponding activate file
- on windows
activate.batset SENDER_ADDR=sender_address set SENDER_PASS=sender_pass set SMTP_PORT=smtp_port set SMTP_SERVER=smtp_server
- on non-windows
activate.shexport SENDER_ADDR=sender_address export SENDER_PASS=sender_pass export SMTP_PORT=smtp_port export SMTP_SERVER=smtp_server
- Using python:
- initialize an instance from the
MailSenderclassfrom mail_sender import MailSender mail_sender = MailSender()
- call the
send_mailmethod and provide the mail attributes:Receiver Address Subject Email Content attached files ( optional)noreply@gmail.com any subject content message attached file list mail_sender.send_mail( receiver_address = "test@gmail.com", subject = "email subject", content = "message content", attach_files = (("filename.ext", file),) )