python 自動傳送郵件

2021-07-24 22:37:35 字數 1601 閱讀 5409

測試環境:

python3.4  

發件伺服器  網易yeah

收件伺服器  移動139郵箱

注意:一定要在發件的郵箱裡面設定pop3/smtp/imap為開啟狀態,要不然會報錯:

535 error:authentication failed

通過本程式,可以自動給自己的手機郵箱傳送郵件,在手機郵箱中把發件位址設定為白名單,就可以在手機收到簡訊通知

測試結果如圖:

#配置資訊

send_mail_host = "smtp.yeah.net" # 傳送的smtp

send_mail_user = "*******" #發件人郵箱的使用者名稱

send_mail_user_name = "李啊湧" #發件人姓名

send_mail_pswd = "********" #發件郵箱設定的授權碼

send_mail_postfix = "yeah.net" # 發郵件的網域名稱

get_mail_user = "***********" #收件使用者名稱

get_mail_postfix = "139.com" #收件人郵箱伺服器

get_mail_host = "pop.139.com" #收件人pop3伺服器

def semd_mail(sub, content):

send_mail_address = send_mail_user_name + ""

msg = email.mime.text.mimetext(content)

msg['subject'] = sub

msg['from'] = send_mail_address

msg['to'] = to_adress = "139smsserver"

try:

stp = smtplib.smtp()

stp.connect(send_mail_host)

stp.login(send_mail_user, send_mail_pswd)

stp.sendmail(send_mail_address, to_adress, msg.as_string())

stp.close()

return true

except exception as e:

print( e)

return false

if __name__ == '__main__':

sub="測試" #主題

content="python如此強大!" #發件內容

if semd_mail(sub, content):

print ("傳送成功")

else:

print( '傳送失敗')

Python自動傳送郵件

本文主要介紹如何使用python實現郵件的自動傳送。首先這個功能要求使用的模組是stmplib,email。smtp message transport protocol 簡單資訊傳輸協議,只能由於傳送郵件。下面是簡要的程式 usr bin python coding utf 8 import sm...

Python 自動傳送郵件

可直接複製進行呼叫 修改main裡對應引數即可 usr bin env python coding utf 8 time 2022 2 11 11 05 author file myemail.py version 1.0 function import datetime import smtpli...

python 自動傳送郵件

import smtplib from email.mime.text import mimetext from email.header import header 配置郵箱資訊 mailhost smtp.qq.com mailuser mailpass 配置傳送人和收件人資訊 sender q...