python直联(适合于企业内部的内网邮箱)发送邮件(带附件)、发送给多人、抄送给多人的示例 | 您所在的位置:网站首页 › 企业邮箱怎么发邮件 › python直联(适合于企业内部的内网邮箱)发送邮件(带附件)、发送给多人、抄送给多人的示例 |
# coding=utf-8 import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header # 发送纯文本格式的邮件 message = MIMEMultipart('related') message.attach(MIMEText('there is some error or warning in your project', 'plain', 'utf-8')) att1 = MIMEText(open('lintResult.txt', 'rb').read(), 'base64', 'utf-8') att1["Content-Type"] = 'application/octet-stream' # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 att1["Content-Disposition"] = 'attachment; filename="aaaa"' message.attach(att1) #发送邮箱地址 sender = '[email protected]' #登陆密码 password = 'eeee' #收件箱地址 receiver = '[email protected], [email protected]' #抄送 acc = '[email protected], [email protected]‘ #smtp服务器 smtp_server = 'ffff' #发送邮箱地址 message['From'] = sender #收件箱地址 message['To'] = receiver message['Cc'] = acc #主题 message['Subject'] = 'this is test email for gggg project' server = smtplib.SMTP(smtp_server,25) server.login(sender,password) server.sendmail(sender,receiver,message.as_string()) server.quit() 很多企业内网或者外网邮箱都是通过邮箱服务器来实现收发邮件并不提供ssh接口,因此需要直联25端口来发送邮件,其中aaaa,bbbb,cccc等需要读者自行替换为所需的东东,其中有些换行或者空格是我后来加入的,可能会出错,需要读者重新替换下 |
CopyRight 2018-2019 实验室设备网 版权所有 |