Envoi de SMS par Free

Il est possible d’envoyer sur son mobile free un sms via une url

Paramétrage du compte Free

Il faut activer sur ce compte Free cette option gratuite afin d’obtenir un clé d’authentification

_images/notification-par-sms.png
_images/cle_service_SMS.png

Envoi d’un sms

via un navigateur e, utilisant l’url

https://smsapi.free-mobile.fr/sendmsg?user=votre_login&pass=votre_passwd&msg=Intrusion_zone_2

ou via un code python

import sys
from optparse import OptionParser

if sys.version_info >= (3,0):
    raw_input = input
    import urllib
    from urllib.parse import *
    from urllib.request import *
else:
    from urllib import *

URL_FREE = 'https://smsapi.free-mobile.fr/sendmsg?%s'

def send_sms(user, authentification, msg):
    params = urlencode({'user' : user,
                                'pass' : authentification,
                                'msg' : msg})
    f = urlopen(URL_FREE % params)
    return True

def get_input(txt, default):
    if len(default):
        return raw_input('%s (%s): ' % (txt, default))
    return raw_input('%s: ' % txt)

if __name__ == '__main__':
    parser = OptionParser(version="smsfree 0.1" ,usage= "usage: smsfree [options]" )
    parser.description= "sens sms by free"
    parser.epilog = "by Frederic Aoustin"
    parser.add_option("-u", "--user",
        dest = "user",
        help = "login for free",
        type = "string",
        default = "")
    parser.add_option("-p", "--password",
        dest = "password",
        help = "authentification for free",
        type = "string",
        default = "")
    parser.add_option("-m", "--msg",
        dest = "msg",
        help = "msg send by sms",
        type = "string",
        default = "")
    (options, args) = parser.parse_args()
    if not len(options.user) or not len(options.password) or not len(options.msg):
        options.user = get_input('user',options.user)
        options.password = get_input('authentification', options.password)
        options.msg = get_input('message', options.msg)
    try:
        send_sms(options.user, options.password, options.msg)
        print('sms send')
    except Exception as e:
        print('sms not send')
        print(parser.error(e))
        parser.print_help()
        sys.exit(1)