Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

Send an email

import smtplib
from email.mime.text import MIMEText
from email.utils import formatdate

FROM_ADDRESS = 'your-email@email-client.com'
TO_ADDRESS = 'recipent@email-client.com'
SUBJECT = 'test mail'
BODY = 'send mail by python'
SMTP_SERVER = 'smtp-mail.outlook.com' # may need to change

def create_message(from_addr, to_addr, subject, body):
    msg = MIMEText(body)
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Date'] = formatdate()
    return msg


def send(from_addr, to_addrs, msg):
    smtpobj = smtplib.SMTP(SMTP_SERVER, 25)
    smtpobj.ehlo()
    smtpobj.starttls()
    smtpobj.sendmail(from_addr, to_addrs, msg.as_string())
    smtpobj.close()


if __name__ == '__main__':

    to_addr = TO_ADDRESS
    subject = SUBJECT
    body = BODY

    msg = create_message(FROM_ADDRESS, to_addr, subject, body)
    send(FROM_ADDRESS, to_addr, msg)
 
PREVIOUS NEXT
Tagged: #Send #email
ADD COMMENT
Topic
Name
9+2 =