python发送短信接口_python发送短信和发送邮件
先注冊(cè)好
發(fā)短信腳本內(nèi)容
#接口類型:互億無(wú)線觸發(fā)短信接口,支持發(fā)送驗(yàn)證碼短信、訂單通知短信等。
#賬戶注冊(cè):請(qǐng)通過(guò)該地址開(kāi)通賬戶http://sms.ihuyi.com/register.html
#注意事項(xiàng):
#(1)調(diào)試期間,請(qǐng)用默認(rèn)的模板進(jìn)行測(cè)試,默認(rèn)模板詳見(jiàn)接口文檔;
#(2)請(qǐng)使用APIID(查看APIID請(qǐng)登錄用戶中心->驗(yàn)證碼短信->產(chǎn)品總覽->APIID)及 APIkey來(lái)調(diào)用接口;
#(3)該代碼僅供接入互億無(wú)線短信接口參考使用,客戶可根據(jù)實(shí)際需要自行編寫;
#!/usr/local/bin/python
#-*- coding:utf-8 -*-
import http.client
import urllib
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"
#用戶名是登錄用戶中心->驗(yàn)證碼短信->產(chǎn)品總覽->APIID
account = "C17089294"
#密碼 查看密碼請(qǐng)登錄用戶中心->驗(yàn)證碼短信->產(chǎn)品總覽->APIKEY
password = "115cfae8f8491834cf3b3xxxxxxx"
def send_sms(text, mobile):
params = urllib.parse.urlencode({'account': account, 'password' : password, 'content': text, 'mobile':mobile,'format':'json' })
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = http.client.HTTPConnection(host, port=80, timeout=30)
conn.request("POST", sms_send_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str
if __name__ == '__main__':
mobile = "1381026xxxx"
text = "您的驗(yàn)證碼是:121254。請(qǐng)不要把驗(yàn)證碼泄露給其他人。"
print(send_sms(text, mobile))
發(fā)郵件
#發(fā)送郵件的庫(kù)
import smtplib
#郵件文本
from email.mime.text import MIMEText
#SMTP服務(wù)器
SMTPServer="smtp.qq.com"
#發(fā)郵件的地址
Sender="525031638@qq.com"
#發(fā)送者郵箱的密碼
passwd="snmvgykwzreixxxx"
#設(shè)置發(fā)送的內(nèi)容
message="I am groot"
#轉(zhuǎn)換成郵件文本
msg=MIMEText(message)
#標(biāo)題
msg["Subject"]="來(lái)自樹(shù)人的問(wèn)候"
#發(fā)送者
msg["From"]=Sender
#創(chuàng)建SMTP服務(wù)器
mailServer=smtplib.SMTP(SMTPServer,25)
#登錄郵箱
mailServer.login(Sender,passwd)
#發(fā)送郵件,其中msg.as_string()是把內(nèi)容轉(zhuǎn)成郵件形式字符串
mailServer.sendmail(Sender,["525031638@qq.com","511243xx@qq.com"],msg.as_string())
#退出郵箱
mailServer.quit()
如果遇到554報(bào)錯(cuò)。,可能是內(nèi)容不合法,也可能是郵箱寫錯(cuò)了
總結(jié)
以上是生活随笔為你收集整理的python发送短信接口_python发送短信和发送邮件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python增量爬虫_python爬虫S
- 下一篇: python统计txt文件中文词频_Py