开发者

How to send SMS using Python/Django application?

I have to develop an application where I need to send SMS to the users on a particular action by the users.

I have heard of kannel with PHP, is there some he开发者_如何转开发lp for the same in Python as well or is there any other better open source sms gateway which I can use with my application?

Please suggest.

Thanks in advance.


Typically you would use normal HTTP GET or POST requests against an SMS Gateway, such as Clickatell and many many others.


Twilio (where I work) has an OSS Python helper library which makes working with their SMS service really easy.


I was struggling with this for some time and really liked the Twilio option. But then I dug deeper and found that there is a Google Voice API called pygooglevoice that works. Clean, easy... No carrier lookup... For example, set up a virtualenv and install with pip:

pip install pygooglevoice

Then use something like this:

from googlevoice import Voice
from googlevoice.util import input

def send(number, message):
    user = 'user@gmail.com'
    password = 'password'

    voice = Voice()
    voice.login(user, password)

    #number = input('Number to send message to: ') # use these for command method
    #message = input('Message text: ')

    voice.send_sms(number, message)

Please note that I have done limited testing with this so I'm not sure all the pros and cons. It's quite possible that there are limitations I haven't discovered yet. But in the time I've played around with it, I've been happy.


[Update] Since the email based solution won't work for you, check out Twilio. Clean APIs, and I hear good things about them.

If you know the carrier the user is on it might be easiest to use the email-to-sms services provided by just about all of the mobile carriers. Here's an article on addresses for many providers.

If that works for you (eg. if you know the number/carrier beforehand or you can ask the user for the carrier as well as their number), then all you have to do is send email to the appropriate address and it'll be sent as an SMS to the user.


Take a look at django-smsgate (BSD licensed) application for working with SMS through SMS gateways.


I just wrote a basic Twilio demo app using Django, which sends SMS messages to users and also processes the SMS responses. I posted the code to github and wrote some explanatory blog posts.

The top level post is here but you can just grab all the code from GitHub. Note that my particular example uses LinkedIn for authentication, but the second and third blog posts cover twilio specific methods. That way you can see if this is an option that'll work for you.

Hope this helps :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜