Skip to main content

A simple Python package for sending messages over SMS Gateways.

Project description

SMS Messenger

A simple Python package for sending messages over SMS Gateways.

Description

SMS Messenger is a simple Python package that enables the user to send and read text messages via SMS Gateways. This package handles all the sending and reading of emails to SMS addresses. Requires an email to setup.

Dependencies

imapclient
pyzmail
An Email Preferably Gmail

Features

  • Simple to use for sending and reading messages
  • easy installation
  • Lightweight with minimal external dependencies
  • Docstrings

Installation

Use the package manager pip to install sms-messenger.

pip install sms_messenger

Usage

import sms_messenger
email = "example@gmail.com"
paswd = "FooBar"
addresses = ['+12003004000@tmomail.net','+15006007000@txt.att.net'] #must specify gateway domain

server = sms_messenger.messageManager(email,paswd) #create a messageManager Object
print(server.getGateways()) #US SMS Gateways
server.sendTextMessage("Hello World!",addresses)

server.sendTextMessage("This is the Body",'tmpEmail@email.com','This is the subject') #works with emails too

replies = server.getTextMessagesFrom('+12003004000@tmomail.net') #needs an address
print(replies)

server.delMessagesToSMS(addresses) #Deletes from Sent Folder

Help

If using gmail, look under the security tab and turn ON Less secure app access.
example.png
It must be on for the package to work.

Docstring

Help on messageManager in module sms_messenger object:

class messageManager(builtins.object)
 |  messageManager(email, paswd, smtp='smtp.gmail.com', port=587)
 |  
 |  A simple class to handle sending and reading text messages via SMS Gateways.
 |  
 |  Dependencies:
 |      imapclient: https://github.com/mjs/imapclient
 |      pyzmail: https://github.com/aspineux/pyzmail
 |  
 |  Attributes:
 |      email: a string containing the email from which the texts will be sent.
 |      paswd: a string containing the password for the email above.
 |      stmp: (optional) a string containing the name of the stmp server.
 |      port: (optional) an int containing the port number to connect to smtp.
 |      SMS_Gateways_US: a dictionary containing the mobile carrier and their respective gateway
 |      GMAIL_FOLDERS: a list containing the respective names of gmail folders
 |      SEARCH_KEYS: a list containing all available search keys
 |  
 |  Methods defined here:
 |  
 |  __init__(self, email, paswd, smtp='smtp.gmail.com', port=587)
 |      Initialize self.
 |      
 |      Note:
 |          If not using gmail, the smtp and port must be specified.
 |  
 |  checkAccess(self)
 |      Attempts to log into the email server
 |      
 |      Returns:
 |          String on success, Nothing otherwise
 |  
 |  delMessagesBySelf(self, folder='[Gmail]/Sent Mail')
 |      Deletes all emails sent.
 |      
 |      Args:
 |          folder: (optional) Folder to be deleted from
 |          
 |      Returns:
 |          String on success, Nothing otherwise
 |  
 |  delMessagesByUIDs(self, UIDs, folder)
 |      Deletes all emails from UID list.
 |      
 |      Args:
 |          UIDs: Python list containing Unique IDs of the emails to be deleted
 |          folder: (optional) Folder to be deleted from
 |          
 |      Returns:
 |          String on success, Nothing otherwise
 |  
 |  delMessagesFromSMS(self, sms_address, folder='INBOX')
 |      Deletes all emails from aspecified sms gateway.
 |      
 |      Args:
 |          sms_address: String containing the sms from which emails will be deleted
 |          folder: (optional) Folder to be deleted from
 |          
 |      Returns:
 |          String on success, Nothing otherwise
 |  
 |  delMessagesToSMS(self, sms_address, folder='[Gmail]/Sent Mail')
 |      Deletes all emails to specified sms gateway.
 |      
 |      Args:
 |          sms_address: List containing the sms to which emails will be deleted
 |          folder: (optional) Folder to be deleted from
 |          
 |      Returns:
 |          Dictionary on success, Nothing otherwise
 |  
 |  getFolders(self)
 |      Returns all the folders available.
 |      
 |      Returns:
 |          List containing all folders availabe
 |  
 |  getGateways(self)
 |      Returns all the US Mobile Carriers and respective SMS Gateways.
 |      
 |      Returns:
 |          SMS_GATEWAYS_US
 |  
 |  getGmailFolders(self)
 |      Returns all Gmail folders.
 |      
 |      Returns:
 |          GMAIL_FOLDERS
 |  
 |  getMessagesFromUIDs(self, UIDs, folder, readOnly=False)
 |      Returns the parsed message from specified UIDs. 
 |      
 |      Args:
 |          UIDs: List of UIDs
 |          folder: folder from which the UIDs came
 |          readOnly: (optional) Whether or not to mark the messages as read.
 |      
 |      Returns:
 |          a dictionary containing the UID and message as a pair.
 |  
 |  getSearchKeys(self)
 |      Returns all search keys.
 |      
 |      Returns:
 |          SEARCH_KEYS
 |  
 |  getTextMessagesFrom(self, sms_address, newMessagesOnly=False, returnUID=False)
 |      Grabs all messages sent by the sms address.
 |      
 |      Retrieves all text messsages sent by the specified sms address.
 |      Only retrieves the body of the email.
 |      
 |      Args:
 |          sms_address: List of strings containing the specified address.
 |          newMessagesOnly: (optional) Only retrieve unread messages
 |          returnUID: (option) Whether or not to return the UIDs
 |      
 |      Returns:
 |          Default:
 |              Python Dictionary containing the sms_address and a list of messages as a pair.
 |              Example
 |      
 |              {'+12003004000@tmomail.net': ['Hello','World'], '+15006007000@tmomail.net': ['foo','bar']}
 |              
 |              To get the message as a list just use exampleDict[sms_address]
 |      
 |          returnUID=True:
 |              Python Dictionary containing the sms_address and a dictionary of UID: message as a pair.
 |              example:
 |      
 |              {'+12003004000@tmomail.net': {123: 'Hello', 456: 'World'}}
 |  
 |  searchFolder(self, folder, *searchKeys)
 |      Searches the specified folder.
 |      
 |      Searches the folder specified by using searchKeys.
 |      Example:
 |          searchFolder('INBOX','FROM','foobar@email.com')
 |          searchFolder('[Gmail]/All Mail','UNSEEN','SUBJECT','Hello World','FROM','foobar@email.com')
 |          
 |      NOTE:
 |          UIDs are folder specific. A UID from INBOX only applies to INBOX.
 |          
 |      Args:
 |          folder: Folder to search from
 |          *searchKeys: List of search keys to be used
 |          
 |      Returns:
 |          List of UIDs for the specified folder.
 |  
 |  sendTextMessage(self, message, sms_address, subject='I am a bot. Beep Boop.')
 |      Sends text message to specified sms_address.
 |      
 |      Composes an email from the message and subject and sends it to the recipients.
 |      Example:
 |          I am a bot. Beep Boop./ Hello World.
 |      
 |      Args:
 |          sms_address: List of strings containing the addresses to be sent
 |          message: Text message to be sent.
 |          subject: (optional) message to be used on subject line.
 |      
 |      Returns:
 |          String on success, Nothing otherwise.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  GMAIL_FOLDERS = ['INBOX', '[Gmail]/All Mail', '[Gmail]/Drafts', '[Gmai...
 |  
 |  SEARCH_KEYS = ['BEFORE', 'ON', 'SINCE', 'SUBJECT', 'BODY', 'TEXT', 'FR...
 |  
 |  SMS_GATEWAYS_US = {'AT&T': 'txt.att.net', 'Alltel': 'sms.alltelwireles...

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sms_messenger-1.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

sms_messenger-1.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file sms_messenger-1.1.0.tar.gz.

File metadata

  • Download URL: sms_messenger-1.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for sms_messenger-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6346cee30cae42000c27be065bdac08fceec7345ff5c079cf37fb3f85ff98b5d
MD5 437e0a3f9cb709b1916cf231a4410078
BLAKE2b-256 c68d7b4651cda4e67610869db34c194bbb3af31026502b30ac0499cb50e583e7

See more details on using hashes here.

File details

Details for the file sms_messenger-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sms_messenger-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for sms_messenger-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15a6be384bb4c7056a3c48c8e90b286419e1fcae5f23b99033c33bfce35ea5dd
MD5 ba74a6abc33df01df35287df90d56d0e
BLAKE2b-256 53d4f7a4bfeb5ab8354cd77bbbbe870659a4c9afcab8bf8edfec6ae076d64add

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page