Python Send mail

Source: Internet
Author: User

Python supports SMTP support with smtplib and email Two modules,email responsible for structuring the message, Smtplib responsible for sending mail

Import smtplib # send mail module

From Email.mime.text import Mimetext # defining message Content

From Email.header Import Header # defining message Headers

# Send Mailbox Server

Smtpserver= ' smtp.163.com '

# Send mailbox user name password

user= ' [email protected] '

Password= ' ... '

# send and receive mailboxes

sender= ' [email protected] '

receive= ' [email protected] '

# Send message subject and content

subject= ' python send mail '

Content= ' python send mail test !

#HTML message body

msg=mimetext(content, ' html ', ' Utf-8 ')

msg[' Subject ']=Header(Subject, ' utf-8 ')

msg[' from ']=sender

Msg[' to '] = Receive

#SSL protocol port number to use 465

SMTP = Smtplib. Smtp_ssl (SmtpServer, 465)

#HELO identify user identities to the server

Smtp. helo (SmtpServer)

# Server returns result confirmation

Smtp. EHLO (SmtpServer)

# Logon Mailbox Server user name and password

Smtp. Login (User,password)

Print (" start sending mail ... ")

Smtp. SendMail (Sender,receive,msg.as_string ())

Smtp. quit ()

Print (" mail sent is complete!") ")

Python Send mail

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.