成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何用python自動發(fā)郵箱

小編給大家分享一下如何用python自動發(fā)郵箱,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

成都創(chuàng)新互聯(lián)是專業(yè)的黔江網(wǎng)站建設(shè)公司,黔江接單;提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行黔江網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

正文

廢話不多說,直接上代碼。

一、普通文本郵件(作通知訓(xùn)練結(jié)束用 :smiley: )

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

import smtplib
from email.mime.text import MIMEText
  
# 第三方 SMTP 服務(wù)
mail_host = "smtp.163.com"  # SMTP服務(wù)器
mail_user = "yourname"  # 用戶名
mail_pass = "xxx"  # 密碼(這里的密碼不是登錄郵箱密碼,而是授權(quán)碼)
  
sender = 'yourname@163.com'  # 發(fā)件人郵箱
receivers = 'othername@163.com']  # 接收人郵箱
  
  
content = 'Python Send Mail ! 訓(xùn)練結(jié)束!'
title = 'Python SMTP Mail 訓(xùn)練結(jié)束'  # 郵件主題

message = MIMEText(content, 'plain', 'utf-8')  # 內(nèi)容, 格式, 編碼
message['From'] = "{}".format(sender)
message['To'] = ",".join(receivers)
message['Subject'] = title
  
try:
    smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 啟用SSL發(fā)信, 端口一般是465
    smtpObj.login(mail_user, mail_pass)  # 登錄驗(yàn)證
    smtpObj.sendmail(sender, receivers, message.as_string())  # 發(fā)送
    print("mail has been send to {0} successfully.".format(receivers))
except smtplib.SMTPException as e:
    print(e)

二、加強(qiáng)版附件傳輸郵件

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

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

# Files' Paths:
file1 = 'mail.py'
file2 = 'maill.py'
# 收郵件的地址,可以多個。
Receivers = ['receiver1@163.com','receiver2@163.com'] 
# 郵件主題:
title = 'Python SMTP 郵件(文件傳輸)'


# 模擬服務(wù)器
# SMTP服務(wù)器
SMTPServer="smtp.163.com"
# 發(fā)郵件的地址
Sender="yourname@163.com"
# 發(fā)送者郵件的授權(quán)密碼,去163郵箱設(shè)置里獲取。并非是密碼。
passwd="xxx"  

# 創(chuàng)建一個帶附件的實(shí)例
message = MIMEMultipart()
message['From'] = Sender
message['To'] = ",".join(Receivers)
message['Subject'] = title
# 郵件正文內(nèi)容
message.attach(MIMEText('附件中是要傳輸?shù)奈募?。\n ', 'plain', 'utf-8'))
message.attach(MIMEText('The files you need are as followed. \n ', 'plain', 'utf-8'))

# 構(gòu)造附件1
att1 = MIMEText(open(file1, 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename={0}'.format(file1)
message.attach(att1)

# 構(gòu)造附件2
att2 = MIMEText(open(file2, 'rb').read(), 'base64', 'utf-8')
att2["Content-Type"] = 'application/octet-stream'
att2["Content-Disposition"] = 'attachment; filename={0}'.format(file2)
message.attach(att2)

try:
    mailServer = smtplib.SMTP(SMTPServer, 25)  # 25為端口號(郵件),0-1024都被系統(tǒng)占用了
    # 登錄郵箱
    mailServer.login(Sender, passwd)  # 需要的是,郵箱的地址和授權(quán)密碼
    # 發(fā)送文件
    mailServer.sendmail(Sender, Receivers, message.as_string())
    print("郵件發(fā)送成功")
    print("Mail with {0} & {1} has been send to {2} successfully.".format(file1,file2,Receivers))
except smtplib.SMTPException as e:
    print("Error: 無法發(fā)送郵件")
    print(e)

后話

可以把代碼加到網(wǎng)絡(luò)train.py的最后,別忘了在train.py的開頭加上:

# -*- coding: UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

然后你就可以專心忙自己的事情,網(wǎng)絡(luò)訓(xùn)練結(jié)束就自動發(fā)郵件啦~

看完了這篇文章,相信你對如何用python自動發(fā)郵箱有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前標(biāo)題:如何用python自動發(fā)郵箱
文章網(wǎng)址:http://jinyejixie.com/article30/ppsiso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、企業(yè)網(wǎng)站制作網(wǎng)站設(shè)計(jì)、建站公司網(wǎng)站策劃、App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管
松溪县| 新建县| 化州市| 江阴市| 江北区| 太原市| 淮安市| 县级市| 凉城县| 万荣县| 滨海县| 滁州市| 六安市| 遂川县| 海林市| 黑龙江省| 九江市| 兖州市| 资兴市| 舒兰市| 屯门区| 新乡市| 万载县| 略阳县| 安远县| 兴文县| 光山县| 云龙县| 黄浦区| 濮阳市| 兴山县| 西林县| 四会市| 从化市| 会泽县| 仁怀市| 壤塘县| 黄平县| 徐闻县| 湖北省| 林口县|