Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from smtplib import SMTP # Use this for standard SMTP protocol (port 25, no encryption)
- # from smtplib import SMTP_SSL as SMTP # This invokes the secure SMTP protocol (port 465, uses SSL)
- from email.mime.text import MIMEText
- class Email(object):
- SMTP_CONFIG = dict(
- server="your_smtp_server_hostname",
- username="your_smtp_server_username",
- password="your_smtp_server_password"
- )
- # typical values for text_subtype are plain, html, xml
- DEFAULT_CONTENT_TYPE = "plain"
- DEFAULT_SENDER = "john.doe@example.com"
- def __init__(self, SMTP_CONFIG=None, debug=False):
- if not SMTP_CONFIG:
- SMTP_CONFIG = self.SMTP_CONFIG
- self.connection = SMTP(SMTP_CONFIG["server"])
- self.connection.set_debuglevel(debug)
- self.connection.login(SMTP_CONFIG["username"], SMTP_CONFIG["password"])
- def send(self, subject, message, receivers, sender=None, content_type=None):
- if not content_type:
- content_type = self.DEFAULT_CONTENT_TYPE
- if not sender:
- sender = self.DEFAULT_SENDER
- msg = MIMEText(message, content_type)
- msg["Subject"] = subject
- msg["From"] = sender
- self.connection.sendmail(sender, receivers, msg.as_string())
- if __name__ == '__main__':
- email = Email()
- email.send("Test", "Test email", ["someone.i.know@gmail.com"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement