|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import smtplib
import socket, getpass, os
from email.mime.text import *
from email.header import *
from email.mime.multipart import *
from email.mime.application import *
host_name = socket.gethostname()
send="XXXXXX"
password='XXXXXXXX'
smtpip = 'XXXXXXX'
receviers=['XXXXXXX']
#邮件内容
message = MIMEText('111test','plain','utf-8')
#邮件主题
#subject = host_name
message['subject'] = Header(host_name,'utf-8')
att1 = MIMEText(open('111.txt','rb').read(),'base64','utf-8')
att1['Content-Type'] = 'application/octet-stream'
att1.add_header('Content-Disposition','attachment',filename = '111.txt')
message.attach(att1)
#实例化对象
smtp = smtplib.SMTP()
#设置连接端口
smtp.connect(smtpip,25)
#账号登录
smtp.login(send,password)
smtp.sendmail(send,receviers,message.as_string())
smtp.quit()
在带附件时出现下面这个报错信息
Traceback (most recent call last):
File "stmpeml.py", line 29, in <module>
message.attach(att1)
File "c:\\Python\Python38\lib\email\mime\nonmultipart.py", line 21, in attach
raise errors.MultipartConversionError(
email.errors.MultipartConversionError: Cannot attach additional subparts to non-multipart/*
在去除添加附件的代码,邮件发送是正常的
源代码中剔除了
发件人
send="XXXXXX"
密码
password='XXXXXXXX'
发送服务器ip
smtpip = 'XXXXXXX'
收件人
receviers=['XXXXXXX']
|
|