-
大小: 2KB文件類型: .py金幣: 1下載: 0 次發(fā)布日期: 2021-05-12
- 語言: Python
- 標(biāo)簽: 樹莓派??外網(wǎng)ip??定時(shí)??郵箱??
資源簡介
python寫的可以在樹莓派,windows, linux, mac平臺上制定時(shí)間發(fā)送設(shè)備所在網(wǎng)絡(luò)的外網(wǎng)ip到自己郵箱
代碼片段和文件信息
#!/usr/bin/env?python3
#?-*-?coding:?utf-8?-*-
#teller@2019-04-26?17:16:11
import?urllib.request
import?urllib.error
import?re
import?os
import?datetime
import?shutil
import?smtplib
from?email.mime.text?import?MIMEText
from?email.mime.multipart?import?MIMEMultipart
from?email.header?import?Header
import?time
def?eSend(sender?receiver?username?password?smtpserver?subject?e_content?file_path?file_name):
????try:
????????message?=?MIMEMultipart()
????????message[‘From‘]?=?sender
????????message[‘To‘]?=?““.join(receiver)
????????message[‘Subject‘]?=?Header(subject?‘utf-8‘)
????????message.attach(MIMEText(e_content?‘plain‘?‘utf-8‘))
????????if?((file_path?!=?None)?and?(file_name?!=?None)):
????????????att1?=?MIMEText(open(file_path+file_name?‘rb‘).read()?‘base64‘?‘utf-8‘)
????????????att1[‘Content-Type‘]?=?‘a(chǎn)pplication/octet-stream‘
????????????att1[‘Content-Disposition‘]?=?“attachment;filename=“+file_name
????????????message.attach(att1)
????????smtp?=?smtplib.SMTP()
????????smtp.connect(smtpserver)
????????smtp.login(username?password)
????????smtp.sendmail(sender?receiver
評論
共有 條評論