#coding=gbk
import smtplib
smtp = smtplib.SMTP()
smtp.connect("smtp.yeah.net", "25")
smtp.login('用户名', '密码')
smtp.sendmail('from@yeah.net', 'to@21cn.com', 'From: from@yeah.net/r/nTo: to@21cn.com/r/nSubject: this is a email from python demo/r/n/r/nJust for test~_~')
smtp.quit()
SMTP.set_debuglevel(level)
SMTP.connect([host[, port]])
SMTP.docmd(cmd[, argstring])
import smtplib, base64, time
userName = base64.encodestring('from').strip()
password = base64.encodestring('password').strip()
smtp = smtplib.SMTP()
smtp.connect("smtp.yeah.net:25")
print smtp.docmd('helo', 'from')
print smtp.docmd('auth login')
print smtp.docmd(userName)
print smtp.docmd(password)
print smtp.docmd('mail from:', '<from@yeah.net>')
print smtp.docmd('rcpt to:', '<from@yeah.net>')
#data 指令表示邮件内容
print smtp.docmd('data')
print smtp.docmd(
'''''from: from@yeah.net
to: from@yeah.net
subject: subject
email body
.
'''
)
smtp.quit()
'''''From: from@yeah.net To: to@21cn.com Subject: test just for test'''
#coding=gbk
import smtplib, mimetypes
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
msg = MIMEMultipart()
msg['From'] = "from@yeah.net"
msg['To'] = 'to@21cn.com'
msg['Subject'] = 'email for tesing'
#添加邮件内容
txt = MIMEText("这是邮件内容~~")
msg.attach(txt)
#添加二进制附件
fileName = r'e:/PyQt4.rar'
ctype, encoding = mimetypes.guess_type(fileName)
if ctype is None or encoding is not None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
att1 = MIMEImage((lambda f: (f.read(), f.close()))(open(fileName, 'rb'))[0], _subtype = subtype)
att1.add_header('Content-Disposition', 'attachment', filename = fileName)
msg.attach(att1)
#发送邮件
smtp = smtplib.SMTP()
smtp.connect('smtp.yeah.net:25')
smtp.login('from', '密码')
smtp.sendmail('from@yeah.net', 'to@21cn.com', msg.as_string())
smtp.quit()
print '邮件发送成功'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有