我们可以通过电子邮件接收 pubnub 通知吗? [英] Can we receive pubnub notifications by email?

查看:62
本文介绍了我们可以通过电子邮件接收 pubnub 通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 NodeJS 发布消息.订阅者是否可以通过电子邮件接收消息?

We are using NodeJS to publish messages. Is it possible for subscribers to receive the messages by email?

推荐答案

PubNub 在 Python 中通过电子邮件通知

Geremy 的回复也是您对 Ruby 的解决方案,我也附上了一个 Python 解决方案.当今实现发送电子邮件的最佳方式是将 PubNub 与 SendGrid 等邮件服务提供商配对,您可以在 Python 中这样做.

PubNub Notifications by Email in Python

Geremy's response also is your solution for Ruby and I'm attaching a Python solution too. The best way to achieve sending an email today is to pair PubNub with a mail service provider such as SendGrid and you would do it like this in Python.

你也可以用 Node.JS 做到这一点npm install sendgrid.下面是 Python 示例:

You can do this with Node.JS too npm install sendgrid. Here follows Python example:

这是一个用法示例:

## Send Email + Publish
publish( 'my_channel', { 'some' : 'data' } )
## Done!

发布 + 电子邮件方法 publish(...)

复制/粘贴以下 python 以在发送电子邮件和发布 PubNub 消息时让您的生活更轻松.我们正在与 SendGrid 电子邮件客户端配对,并附上 pip 存储库.

Publish + Email method publish(...)

Copy/paste the following python to make your life easy when sending an Email and Publishing a PubNub message. We are pairing with SendGrid email client and the pip repo is attached.

## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Send Email and Publish Message on PubNub
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
import Pubnub    ## pip install Pubnub
import sendgrid  ## pip install sendgrid

def publish( channel, message ):
    # Email List
    recipients = [
        [ "john.smith@gmail.com", "John Smith" ],
        [ "jenn.flany@gmail.com", "Jenn Flany" ]
    ]

    # Info Callback
    def pubinfo(info): print(info)

    # Connection to SendGrid
    emailer = sendgrid.SendGridClient( 'user', 'pass',  secure=True )
    pubnub = Pubnub( publish_key="demo", subscribe_key="demo", ssl_on=True )

    # PubNub Publish
    pubnub.publish( channel, message, callback=pubinfo, error=pubinfo )

    # Email Message Payload
    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))

    ## Add Email Recipients
    for recipient in recipients:
        email.add_to("%s <%s>" % (recipient[1], recipient[0]))

    ## Send Email
    emailer.send(email)

这篇关于我们可以通过电子邮件接收 pubnub 通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆