发送普通邮件importsmtplibfromsmtplibimportSMTP_SSLfromemail.mime.textimportMIMETextfromemail.mime.multipartimportMIMEMultipartfromemail.headerimportHeaderhost_server="smtp.sina.com"sender_sina="fuxingyu_123@sina.com"pwd="xxxxx"sender_sina_mail="fuxingyu_123@sina.com"#发件人邮箱receiver="280568238@qq.com"mail_title="Foundation"mali_content="hahahaha"msg=MIMEMultipart()#邮件主题msg["Subject"]=Header(mail_title,'utf-8')msg["From"]=sender_sina_mailmsg["To"]=Header("测试邮件","utf-8")msg.attach(MIMEText(mali_content,"plain","utf-8"))#mailtextsmtp=SMTP_SSL(host_server)#sslloginsmtp.login(sender_sina,pwd)smtp.sendmail(sender_sina_mail,receiver,msg.as_string())smtp.quit()发送带有附件的邮件importsmtplibfromsmtplibimportSMTP_SSLfromemail.mime.textimportMIMETextfromemail.mime.multipartimportMIMEMultipartfromemail.mime.applicationimportMIMEApplication#addattachmentfromemail.headerimportHeaderhost_server="smtp.sina.com"发件人_sina="fuxingyu_123@sina.com"pwd="xxxxxx"sender_sina_mail="fuxingyu_123@sina.com"#发件人邮箱receiver="280568238@qq.com"mail_title="fund"mali_content="今天是快乐的一天"attchment=MIMEApplication(open("C://Users//fuxingyu//桌面//food.xlsx","rb").read())attchment.add_header("Content-Disposition","attachment",filename="food.xlsx")msg=MIMEMultipart()#Mailbodymsg["主题"]=Header(mail_title,'utf-8')msg["From"]=sender_sina_mailmsg["To"]=Header("测试邮件","utf-8")msg.attach(MIMEText(mali_content,"plain","utf-8"))#邮件正文msg.attach(attchment)#添加附件
