Send SMS via Gmail SMTP servers.
pysendsms is a quick and simple way to use python to send SMS via Gmail SMTP servers to known a cell carrier.
Use the package manager pip to install pysendsms.
pip install pysendsms
- A Gmail account with app specific password enabled for use. Manage Google Apps
- Knowledge of which cell carrier provider the receiving party uses.
Import the library and create and SMS Object utilizing your gmail account and an application password created within your Google account.
import pysendsms sms = pysendsms.SMS('<username>@gmail.com', '<password>')
Create an Contact object using the persons phone number and select a carrier from the avaible options.
CARRIERS is a json file in the project that can be checked for available carriers that can be used for messaging.
contact = pysendsms.Contact('311-555-2368', pysendsms.CARRIERS['AT&T'])
Use the SMS.send() method of your SMS object, passing the Contact and the message you would like to send as a string.
sms.send(contact, 'Hello, World!')
SMS.send() can also accept a list of contacts for sending out group messages.
group = [contact, contact, contact, contact] sms.send(group, 'Everyone gets a message!')
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.