Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Send an email in Python

Send an email - Python:


import smtplib

def send_email(subject, msg):
    try:
        server = smtplib.SMTP('smtp.gmail.com:587')
        server.ehlo()
        server.starttls()
        server.login("youremailusername", "password")
        message = 'Subject: {}\n\n{}'.format(subject, msg)
        server.sendmail("[email protected]", "[email protected]", message)
        server.quit()
        print("Success: Email sent!")
    except:
        print("Email failed to send.")

subject = "An email with attachment from Python"
msg = "This is an email with attachment sent from Python"

send_email(subject, msg)
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)