首页 > 代码库 > python发送邮件
python发送邮件
# -*- coding: UTF-8 -*- ‘‘‘ 发送txt文本邮件 ‘‘‘ import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart msg = MIMEMultipart() att1 = MIMEText(open(‘E:\自动对账.rar‘, ‘rb‘).read(), ‘base64‘, ‘gb2312‘) att1["Content-Type"] = ‘application/octet-stream‘ att1["Content-Disposition"] = ‘attachment; filename="123456.rar"‘#这里的filename可以任意写,写什么名字,邮件中显示什么名字 msg.attach(att1) text=MIMEText("hello how are you\ndddddd ") # text.replace_header(‘Content-Transfer-Encoding‘,‘quoted-printable‘) msg.attach(text) mailto_list = [‘691408557@qq.com‘] mail_host = "webmail.meryer.com" # 设置服务器 mail_user = "market04" # 用户名 mail_pass = "liu#123" # 口令 mail_postfix = "meryer.com" # 发件箱的后缀 def send_mail(to_list, sub, content): me = "hello" + "<" + mail_user + "@" + mail_postfix + ">" # msg = MIMEText(content, _subtype=‘plain‘, _charset=‘gb2312‘) msg[‘Subject‘] = sub msg[‘From‘] = me msg[‘To‘] = ";".join(to_list) try: server = smtplib.SMTP() server.connect(mail_host) server.login(mail_user, mail_pass) server.sendmail(me, to_list, msg.as_string()) server.close() return True except Exception: print(‘错误‘) return False if __name__ == ‘__main__‘: if send_mail(mailto_list, "hello", "hello world"): print("发送成功") else: print("发送失败")
python发送邮件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。