通过Gmail SMTP服务器发送短信。
pysendsms的Python项目详细描述
PySendSMS公司
pysendsms是一种使用python通过Gmail或任何其他SMTP服务器向已知的蜂窝运营商发送短消息的快速而简单的方法。
安装
使用包管理器pip安装pysendsms。
pip install pysendsms
需要
- 启用了应用程序特定密码的Gmail帐户。Manage Google Apps
Note: Other SMTP servers can be used, however configuration varies by providers. Gmail is setup to work by default just requiring email and password.
- 接收方使用哪个蜂窝载波提供商的知识。在
使用
导入库并使用你的gmail帐户和在Google帐户中创建的应用程序密码创建一个SMS对象。
^{pr2}$SMS对象有各种参数,允许您使用您选择的其他一些SMTP提供程序。
sms=pysendsms.SMS(self,username='<username>@gmail.com',password='<app-password>',from_email=None,server='smtp.gmail.com',port=587,tls=True)
Note: If using an SMTP API and you are given a username that is not an email address, you must provide the a verified from_email parameter otherwise outgoing mail with fail.
使用个人电话号码创建联系人对象,并从可用选项中选择运营商。
CARRIERS是从项目中的json文件加载的字典,可以检查可用于消息传递的可用载体。
>>>pysendsms.Contact('2715552343','AT&T')<Contact('2715552343','@mms.att.net')>
也可以使用by_address类方法使用已知地址创建联系人。
>>>pysendsms.Contact.by_address('2715552343@mms.att.com')<Contact('2715552343@mms.att.com')>
Note: Given the nature of this capability, you are able to just add any email address here and not one linked to a phone number for standard SMTP emailing functionality.
使用短信发送()方法,以字符串形式传递联系人和要发送的消息。这也可以接受发送群消息的联系人列表。
contact1=pysendsms.Contact('311-555-2368','AT&T')sms.send(contact1,'Hello, World!')contact2=pysendsms.Contact.by_address('3115552368@mms.att.net')group=[contact1,contact2]sms.send(group,'Everyone gets a message!')
许可证
- 项目
标签: