python发送短信接口_python发送短信和发送邮件
先注冊好
發(fā)短信腳本內(nèi)容
#接口類型:互億無線觸發(fā)短信接口,支持發(fā)送驗證碼短信、訂單通知短信等。
#賬戶注冊:請通過該地址開通賬戶http://sms.ihuyi.com/register.html
#注意事項:
#(1)調(diào)試期間,請用默認的模板進行測試,默認模板詳見接口文檔;
#(2)請使用APIID(查看APIID請登錄用戶中心->驗證碼短信->產(chǎn)品總覽->APIID)及 APIkey來調(diào)用接口;
#(3)該代碼僅供接入互億無線短信接口參考使用,客戶可根據(jù)實際需要自行編寫;
#!/usr/local/bin/python
#-*- coding:utf-8 -*-
import http.client
import urllib
host = "106.ihuyi.com"
sms_send_uri = "/webservice/sms.php?method=Submit"
#用戶名是登錄用戶中心->驗證碼短信->產(chǎn)品總覽->APIID
account = "C17089294"
#密碼 查看密碼請登錄用戶中心->驗證碼短信->產(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 = "您的驗證碼是:121254。請不要把驗證碼泄露給其他人。"
print(send_sms(text, mobile))
發(fā)郵件
#發(fā)送郵件的庫
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)
#標題
msg["Subject"]="來自樹人的問候"
#發(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報錯。,可能是內(nèi)容不合法,也可能是郵箱寫錯了
總結(jié)
以上是生活随笔為你收集整理的python发送短信接口_python发送短信和发送邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python增量爬虫_python爬虫S
- 下一篇: python统计txt文件中文词频_Py