python使用两种发邮件的方式smtp和outlook示例
smtp是直接调用163邮箱的smtp服务器,需要在163邮箱中设置一下。outlook发送就是Python直接调用win32方式。调用程序outlook直接发送邮件。
importwin32com.clientaswin32
importxlrd
outlook=win32.Dispatch('outlook.application')
mail=outlook.CreateItem(0)
receivers=['Yutao.A.Wang@alcatel-sbell.com.cn']
mail.To=receivers[0]
mail.Subject='test1'
workbook=xlrd.open_workbook('E:\\kpiexcel\\00_summary.xls')
mySheet=workbook.sheet_by_index(0)
nrows=mySheet.nrows
content=[]
foriinrange(nrows):
ss=mySheet.row_values(i)
content.append(ss)
print(content)
Truecontent=str(content)
mail.Body=Truecontent
mail.Attachments.Add('E:\\kpiexcel\\00_summary.xls')
mail.Send()
smtp发送邮件
importsmtplib
fromemail.mime.textimportMIMEText
mail_host='smtp.163.com'
mail_user='18298268658'
mail_pass='cat123'
sender='18298268658@163.com'
receivers=['619538553@qq.com']
message=MIMEText('content','plain','utf-8')
message['Subject']='title'
message['From']=sender
message['To']=receivers[0]
try:
smtpObj=smtplib.SMTP()
smtpObj.connect(mail_host,25)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(
sender,receivers,message.as_string())
smtpObj.quit()
print('success')
exceptsmtplib.SMTPExceptionase:
print('error',e)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下