python 邮件发送

#!/usr/bin/env python

# -*- coding:UTF-8 -*-

#需要在邮箱处设置开启SMTP服务(第三方客户端发送)

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
def mail():
ret = True
try:
msg = MIMEText(‘测试邮件‘,‘plain‘,‘utf-8‘)
msg[‘From‘] = formataddr([‘18664988372‘,‘[email protected]‘])
msg[‘To‘] = formataddr([‘18664988372‘,‘[email protected]‘])
msg[‘Subject‘] = ‘主题‘

server = smtplib.SMTP("smtp.163.com",25)

server.login("[email protected]",‘wasver60‘)  #wasver60是授权第三方登录的密码

server.sendmail("[email protected]",["[email protected]",],msg.as_string())
server.quit()
except Exception:
ret = False
return ret

result = mail()
if result == True:
print ("邮件发送成功")
else:
print ("邮件发送失败")

时间: 2024-10-23 05:59:58

python 邮件发送的相关文章

python邮件发送

在基于互联网的应用中,程序经常需要自动地发送电子邮件.如:一个网站的注册系统会在用户注册时发送一封邮件来确认注册:当用户忘记登陆密码的时候,通过邮件来取回密码.smtplib模块是python中smtp(简单邮件传输协议)的客户端实现.我们可以使用smtplib模块,轻松的发送电子邮件.下面的例子用了不到十行代码来发送电子邮件: #coding=gbk import smtplib smtp = smtplib.SMTP() smtp.connect("smtp.yeah.net", 

python邮件发送开服记录

#-*-coding:utf-8 -*- #!/usr/bin/python import sys reload(sys) # reload 才能调用 setdefaultencoding 方法 sys.setdefaultencoding('utf-8') # 设置 'utf-8' import MySQLdb import houtai_dbname from email.mime.text import MIMEText from email.header import Header im

Python邮件发送脚本(Linux,Windows)通用

脚本 #!/usr/bin/python #-*- coding:utf-8 -*- #Python Mail for chenglee #if fileformat=dos, update fileformat=unix #code:set fileformat=unix #check:set ff ? import smtplib from email.mime.text import MIMEText from email.utils import formataddr my_sender

Python邮件发送源码

从最初的实现邮件发送功能,改了几次,有了如下代码. 该代码还可以继续开发,完善.以实现更复杂的功能. #-*- coding:utf-8 -*- i = 0 while i < 10: import smtplib from email.mime.text import MIMEText from email.header import Header import time # 第三方 SMTP 服务 mail_host="smtp.qq.com" #设置服务器 mail_use

python邮件发送脚本

转自:http://phinecos.cnblogs.com/ 1 #!/usr/bin/python 2 #coding=utf-8 3 4 #@author:dengyike 5 #@date:2010-09-28 6 #@version:1.0 7 #@description: auto sending email with attachment file 8 9 import email 10 import mimetypes 11 from email.MIMEMultipart im

python 邮件发送的代码 网上的方法汇总一下

一.文件形式的邮件 #!/usr/bin/env python3#coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Header sender = '***'receiver = '***'subject = 'python email test'smtpserver = 'smtp.163.com'username = '***'password = '***' msg

python 邮件发送 zabbix 图片

获取图片 http://www.iyunv.com/thread-21332-1-1.html 邮件内嵌图片 http://www.tuicool.com/articles/vaAVri

Python邮件发送功能

import smtplibfrom email.mime.text import MIMEText_user = "[email protected]"#发件人_pwd = "wcpxldrtuthagjbc"#qq邮箱授权码_to = "[email protected]"#收件人 msg = MIMEText("Hellow,This is my first Email!")#邮件内容msg["Subject&

python邮件发送代码

1.通过socket 1 In [1]: import socket 2 3 In [2]: smtp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 4 5 In [3]: smtp.connect(("163mx00.mxmail.netease.com", 25)) 6 7 In [4]: smtp.send("Hello Mr He.\r\n") 8 Out[4]: 14 9 10 In [5]: sm