Python郵件與CentOS郵件

2021-10-06 02:31:52 字數 1796 閱讀 5201

背景:由於專案需要對每日資料進行比對監控,所以需要把比對結果傳送給各負責人,本文記錄下python傳送郵件的幾個步驟。

需要模組:smtplib

pip install smtplib
閒言少敘上**

# -*- coding: utf-8 -*-

from email.header import header

from email.mime.text import mimetext

import smtplib

#傳送郵箱

sender='***[email protected]'

password='*********x'

#接受郵箱

receiver='*********@qq.com'

smtpserver='smtp.qq.com'

subject='郵件傳送測試'

msg=mimetext('測試內容請忽略','plain','utf-8')

msg['subject']=header(subject,'utf-8')

msg['to']=receiver

msg['from']=sender

try:

smtp=smtplib.smtp()

smtp.connect(smtpserver)

smtp.login(sender,password)

smtp.sendmail(sender,receiver,msg.as_string())

smtp.quit()

print ("郵件傳送成功")

except smtplib.smtpexception as e:

print (e)

需要注意的是login的密碼並不是郵箱密碼而是開啟smpt/pop服務的驗證碼,去郵箱開啟設定即可。

由於很多公司的內部郵箱都沒有開啟25埠,25埠是預設的發件埠,為了資料安全使用465埠傳送ssl加密郵件,**只需要微調即可

# -*- coding: utf-8 -*-

from email.header import header

from email.mime.text import mimetext

import smtplib

#傳送郵箱

sender='***[email protected]'

password='*********x'

#接受郵箱

receiver='*********@qq.com'

smtpserver='smtp.qq.com'

subject='郵件傳送測試'

msg=mimetext('測試內容請忽略','plain','utf-8')

msg['subject']=header(subject,'utf-8')

msg['to']=receiver

msg['from']=sender

try:

# 使用smpt_ssl方法傳送加密郵件

smtp=smtplib.smtp_ssl(smtpserver, 465)

smtp.login(sender, password)

smtp.sendmail(sender, receiver, msg.as_string())

smtp.quit()

print("郵件傳送成功")

except smtplib.smtpexception as e:

print (e)

centos傳送郵件 網易

步驟1 root backup rpm qa mailx 我這裡已經安裝了,就不再安裝了。mailx 12.5 19.el7.x86 64 root backup rpm qa postfix postfix 2.10.1 7.el7.x86 64 確保這兩個軟體已經安裝 步驟2 編輯配置檔案 步驟...

python 發郵件 python發郵件

python提供smtplib模組,該模組定義了乙個smtp客戶端會話物件,可用於使用smtp或esmtp偵聽器守護程式向任何網際網路機器傳送郵件。這是乙個簡單的語法,用來建立乙個smtp物件,稍後將演示如何用它來傳送電子郵件 import smtplib smtpobj smtplib.smtp ...

centos 使用 mail 傳送郵件

這是在解決mysql自動備份的時候需要做的,單獨拿出來記錄一下 首先163開通smtp pop3並開通設定授權碼 centos主機上,執行如下命令安裝sendmail。yum y install sendmail systemctl start sendmail yum install y mail...