Python3 and python3

Source: Internet
Author: User

Python3 and python3

The instance is as follows:

#! /Usr/bin/python #-*-coding: UTF-8-*-import smtplibimport email. mime. multipartimport email. mime. textfrom email. mime. text import MIMETextfrom email. mime. multipart import MIMEMultipartfrom email. mime. application import MIMEApplicationdef send_email (smtpHost, sendAddr, password, recipientAddrs, subject = '', content =''): msg = email. mime. multipart. MIMEMultipart () msg ['from'] = sendAddr msg ['to'] = reci PientAddrs msg ['subobject'] = subject content = content txt = email. mime. text. MIMEText (content, 'plain ', 'utf-8') msg. attach (txt) # Add an attachment and send the file D:/mydev/yasuo.rar part = MIMEApplication (open ('d:/mydev/6.rar ', 'rb '). read () part. add_header ('content-disposition', 'attachment', filename = "yasuo.rar") msg. attach (part) smtp = smtplib. SMTP () smtp. connect (smtpHost, '25') smtp. login (sendAddr, password) smtp. send Mail (sendAddr, recipientAddrs, str (msg) print ("sent successfully! ") Smtp. quit () try: subject = 'python test mail' content = 'This is a test email written in Python. 'Send _ email ('smtp .163.com ', '192 @ 163.com', 'mailbox password', '192 @ qq.com ', subject, content) cannot Exception as err: print (err)

The above example of sending any file email in python3 is all the content shared by xiaobian. I hope to give you a reference and support for the customer's house.

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.