Python allows you to send emails and attachments.
Today, I want to tell you how to send an email to python. I have to go to Baidu for additional official words. I still have a lot of documents to tell you the truth, so most people will not go to it. I will go back to the topic:
If the mac is not based on the dependent module, install it as follows:
If there is no error in the import module, the installation is successful.
Python sends an unknown MIME-type file attachment. The basic idea is as follows:
1. Construct the MIMEMultipart object as the root container
2. Construct the MIMEText object as the mail display content and attach it to the root container
3. Construct the MIMEBase object as the file attachment content and attach it to the root container
A. Read and format the file content.
B. Set the attachment Header
4. Set root container Properties
5. Obtain the formatted complete text.
6. Send emails using smtp
Instance code:
#! /Usr/bin/env python #-*-coding: UTF-8-*-import smtplib from email. mime. multipart import MIMEMultipart from email. mime. text import MIMEText from email. mime. application import MIMEApplication class Mailer (object): def _ init _ (self, maillist, mailtitle, mailcontent): self. mail_list = maillist self. mail_title = mailtitle self. mail_content = mailcontent self. mail_host = "smtp.163.com" self. mail_user = "Your email name" self. mail_pass = "your email password" self. mail_postfix = "163.com" def sendMail (self): me = self. mail_user + "<" + self. mail_user + "@" + self. mail_postfix + ">" msg = MIMEMultipart () msg ['subobject'] = 'python mail test' msg ['from'] = me msg ['to'] = "; ". join (self. mail_list) # puretext = MIMEText ('
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.