python 郵件傳送學習

2021-10-16 22:48:55 字數 1008 閱讀 7210

"""

@author:ouyang_test

@time :2021/1/20 15:01

"""import smtplib

from email.header import header

from email.mime.text import mimetext

def send_mail(sender, password, receiver):

# 郵件伺服器

smtpserver = "smtp.163.com"

# 發件人和客戶端授權

mail_sender = sender

mail_pass = password

# 接收人

mail_receiver = receiver

# 郵件主題

subject = "郵件測試"

# 連線登陸發件箱

server = smtplib.smtp(smtpserver, 25)

server.login(mail_sender, mail_pass)

msg = mimetext("恭喜你,成功通過了考試!", "plain", "utf-8") # 正文內容、郵件型別、編碼

msg["from"] = mail_sender

msg["to"] = mail_receiver

msg["subject"] = header(subject, "utf-8").encode()

# 傳送郵件

try:

server.sendmail(mail_sender, mail_receiver, msg.as_string())

server.quit()

print("郵件傳送成功")

except smtplib.smtpexception as e:

print("郵件傳送失敗!" % e)

if __name__ == '__main__':

send_mail()

python 傳送郵件學習

import smtplib from email.mime.text import mimetext 傳送文字檔案 from email.utils import formataddr 郵箱位址和口令 sender addr 14 xx qq.com 發件人郵箱 password x 這裡的密碼是...

郵件學習 python傳送郵件分析

首先呼叫python傳送乙個郵件 usr bin python3 import smtplib from email.mime.text import mimetext from email.utils import formataddr my sender 111111111 qq.com 發件人...

學習使用python傳送郵件

使用python傳送郵件 import os import smtplib import mimetypes from email.mimemultipart import mimemultipart from email.mimebase import mimebase from email.mi...