PubNub email notifications in Python
Geremy's answer is also your solution for Ruby , and I am attaching a Python solution . The best way to get your email sent today is to install PubNub with a mail service provider such as SendGrid, and you will do it like in Python.
You can do this with Node.JS too npm install sendgrid. The following is an example of Python:
Here is a usage example:
publish( 'my_channel', { 'some' : 'data' } )
+ publish(...)
/ python, PubNub. SendGrid repopo.
import Pubnub
import sendgrid
def publish( channel, message ):
recipients = [
[ "john.smith@gmail.com", "John Smith" ],
[ "jenn.flany@gmail.com", "Jenn Flany" ]
]
def pubinfo(info): print(info)
emailer = sendgrid.SendGridClient( 'user', 'pass', secure=True )
pubnub = Pubnub( publish_key="demo", subscribe_key="demo", ssl_on=True )
pubnub.publish( channel, message, callback=pubinfo, error=pubinfo )
email = sendgrid.Mail()
email.set_from("PubNub <pubsub@pubnub.com>")
email.set_subject("PubNub Message")
email.set_html(json.dumps(message))
email.set_text(json.dumps(message))
for recipient in recipients:
email.add_to("%s <%s>" % (recipient[1], recipient[0]))
emailer.send(email)