python 发送邮件短信封装
发送邮件
需要开启163的smtp服务

import smtplib
from email.mime.text import MIMEText class MailSender(): def __init__(self,sender,recever,content,password,subject="",server="smtp.163.com",port=994):
""" :param sender: 发送方邮箱
:param recever: 接收方邮箱 ,字符串存储 ','分割
:param content: 发送正文
:param password: 发送方授权码
:param subject: 主题可以为空
:param server: 邮件服务器地址
:param port: 邮件服务器端口
"""
self.subject = subject
self.content = content
self.sender = sender
self.password = password
self.server = server
self.port = port self.message = MIMEText(content, "plain", "utf-8")
self.message["Subject"] = subject
self.message["From"] = sender
self.message["To"] = recever def send(self):
smtp = smtplib.SMTP_SSL("smtp.163.com", 465)
smtp.login(sender, password)
try:
smtp.sendmail(sender, recever.split(","), self.message.as_string()) except Exception as e:
print(e)
finally:
if smtp:
smtp.close() if __name__ == '__main__':
subject = "李青" content = """双眼失明从来不影响我""" sender = "1503760xxxx@163.com" # 解决554 DT:SPM错误,把自己的邮箱加入里面
recever = "1503760xxxx@163.com,2533636371@qq.com,318750798@qq.com"
password = "xxxx" mailsend = MailSender(sender=sender,recever=recever,password=password,content=content)
mailsend.send()
发送手机验证码
需要在https://user.ihuyi.com/index.html注册,使用APIID和APIKEY发送

import requests #pip install requests url = "http://106.ihuyi.com/webservice/sms.php?method=Submit" #来自于文档
#APIID
account = ""
#APIkey
password = ""
mobile = "1503760xxxxx" # 接收手机号
content = "您的验证码是:135279。请不要把验证码泄露给其他人。"
headers = {
"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
}
#构建发送参数
data = {
"account": account,
"password": password,
"mobile": mobile,
"content": content,
}
#开始发送
response = requests.post(url,headers = headers,data=data)
#url 请求接口路由
#headers 请求头部
#data 请求的内容
print(response.content.decode())
钉钉发送群机器人发送,DING_URL为webhook

import random
# 随机生成验证码
def random_code(len=4): string = "".join([str(i) for i in range(0,10)])+"".join([chr(i)+chr(i).lower() for i in range(65,90)])
return "".join([random.choice(string) for i in range(len)]) import json
import requests # to 接收方
def sendDing(content,to=""):
DING_URL = """https://oapi.dingtalk.com/robot/send?access_token=90b5894a1615f70278806be3dd9ce6cd7e959bc1093df9a3b2845e22ede24279"""
headers = {
"Content-Type": "application/json",
"Charset": "utf-8"
}
requests_data = {
"msgtype": "text",
"text": {
"content": content
},
"at": {
"atMobiles": [
],
"isAtAll": True
}
}
if to:
requests_data["at"]["atMobiles"].append(to)
requests_data["at"]["isAtAll"] = False
else:
requests_data["at"]["atMobiles"].clear()
requests_data["at"]["isAtAll"] = True
sendData = json.dumps(requests_data)
response = requests.post(url=DING_URL, headers=headers, data=sendData)
content = response.json()
return content if __name__ == '__main__':
print(random_code())
python 发送邮件短信封装的更多相关文章
- Python发送短信提醒
Python发送短信可借助腾讯云平台提供的短信服务 发送短信需要的及格参数: 1.SDK_AppID和SDK_Key 2.签名: 3.模板ID 下面贴出源码DEMO: from qcloudsms_p ...
- 使用python进行短信轰炸
本文作者:i春秋作家——Hacker1ee 大家好,我是1ee(因为在作家群,就不加Hacker这个前缀了,怕被大佬打..) 刚加入i春秋作家组希望大家多多关照,也欢迎大家找我交流 今天我来讲讲我最近 ...
- python发送短信和发送邮件
先注册好 发短信脚本内容 #接口类型:互亿无线触发短信接口,支持发送验证码短信.订单通知短信等. #账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html ...
- 使用python实现短信PDU编码
前几天入手一个3G模块,便倒腾了一下.需要发送中英文混合短信,所以采用PDU模式(不了解google ^_^). 最大问题当然就是拼接PDU编码(python这么强大,说不定有模块),果不其然找到一个 ...
- DAY3 python群发短信
手机轰炸,burpsuit 抓取注册页面输入的手机号,然后每点击一次forword ,都开开始放行,发短信.也可以发到repeat 里面进行 ,重复发送短信. import requests impo ...
- python发送短信验证码
业务: 手机端点击发送验证码,请求发送到python端,由python调用第三方平台(我们使用的是榛子云短信http://smsow.zhenzikj.com)的短信接口,生成验证码并发送. SDK下 ...
- python twilio 短信群发 知识留存
1. win7 32位系统,傻瓜安装Anaconda2(python 2.7) 2. 打开cmd, 输入命令pip install twilio,在线安装twilio 3. 打开Anaconda2的S ...
- 使用 Python 发送短信?
上回食行生鲜签到,我们说到怎么把签到结果发出来,于是就找到了 Twilio. Twilio 是一个位于加利福尼亚的云通信(PaaS)公司,致力于为开发者提供通讯模块的 API.由于 Twilio 为试 ...
- ThreadPoolTaskExecutor异步的处理报警发送邮件短信比较耗时的东东
package com.elong.ihotel.util; import org.springframework.beans.factory.DisposableBean; import org.s ...
随机推荐
- Spring 框架中Http请求处理流程
Spring Web http request请求流程: 首先介绍这边你需要知道的继承体系,DispacherServlet继承自FrameworkServlet,FrameworkServlet继承 ...
- leetcode-129-求根到叶子结点数字之和
题目描述: 第一次提交: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self. ...
- 第九章 Odoo 12开发之外部 API - 集成第三方系统
Odoo 服务器端带有外部 API,可供网页客户端和其它客户端应用使用.本文中我们将学习如何在我们的客户端程序中使用 Odoo 的外部 API.为避免引入大家所不熟悉的编程语言,此处我们将使用基于 P ...
- BZOJ 1579 [Usaco2009 Feb]Revamping Trails 道路升级
堆优化的dijkstra. 把一个点拆成k个. 日常空间要开炸一次.. //Twenty #include<cstdio> #include<cstring> #include ...
- AFO之后……
先上游记:@ 据说有一种东西叫狗屁不通文章生成器:@
- System.Web.Mvc.ViewEngineResult.cs
ylbtech-System.Web.Mvc.ViewEngineResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, P ...
- NAT后的FTP服务器部署笔记
(2019年2月19日注:这篇文章原先发在自己github那边的博客,时间是2017年2月5日) 寒假开始以后,过年之前有一个任务,为实验室的人搭建一个FTP,用之前部署好的物理服务器.这本就是网管干 ...
- 转:Wireshark基本介绍和学习TCP三次握手
源地址:http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html 之前写过一篇博客:用 Fiddler 来调试HTTP,HTTPS ...
- Access数据库连接字符串
<connectionStrings> <add name="connStr" connectionString="server=.;uid=home; ...
- HBase Ganglia