如何从电子邮件回复聊天对话
How to reply to the chat conversation from an email
我必须创建一个功能,当任何用户在聊天中进行任何对话时,都会向其他聊天用户生成一封电子邮件。其他用户可以查看电子邮件,并且可以从同一封电子邮件回复到聊天对话中。我正在使用 angular 流星。我怎样才能实现这个功能? sendgrid 或 mailgun 中是否有任何 API 来处理来自电子邮件的呼叫并添加对话?或者我必须创建 POST/GET 方法来接受点击邮件中按钮的调用并保存回复文本?
您可以告诉 sendgrid 在收到传入电子邮件时对您的服务器执行 REST api 调用。
发送电子邮件时,将回复电子邮件设置为@chat-reply.myserver.com
然后您在服务器代码中设置一个端点来处理这些请求。您的代码将需要从传入地址查找对话,然后它可以在聊天中保存一条记录。
这是一些代码...
import { Meteor } from 'meteor/meteor'
formidable = require('formidable'); // Formidable does upload form/file parsing
import { Profiles } from '../imports/api/collections';
import { inboundReply } from '../imports/api/inbound/methods.js';
const debug = require('debug')('myapp:inbound')
// Needs to run on the server and client, why this is not in the routing.js file
// which is only only runs on the client.
// Inbound emails, for loop reply
//
// This is a RESTAPI end point which is called by sendgrid,
// any email to xxxx@chat-reply.myserver.com.au will come here. Our job
// is to parse it , work out which loop it relates to, and save it as a message
// in the database
//
Router.route('/inbound', function () {
// Need to use formidable because SendGrid inbound data is encoded as a multipart/form-data
const form = new formidable.IncomingForm();
// Meteor bind eviron. to get callback
debug(this.request.body)
let r = this.response
form.parse(this.request, Meteor.bindEnvironment(function (error, fields, files) {
if (error)
console.error(error);
let errs = []
// Gets the to field
const toField = _.find(fields, function(value, key) { if (key === 'to') { return value; }});
// Gets the from field
const fromField = _.find(fields, function(value, key) { if (key === 'from') { return value; }});
// Gets the html content, email
const content = _.find(fields, function(value, key) { if (key === 'text') { return value; }});
let cleanContent;
if (content){
// Logger.trace({content: content});
// Regex removes html
// cleanContent = content.replace(/<br>/ig, "\n");
// const regex = /(<([^>]+)>)/ig
// cleanContent = cleanContent.replace(regex, "");
// Logger.trace({cleanContent: cleanContent});
let lines = content.split(/\n/);
debug("Incoming body",lines);
我必须创建一个功能,当任何用户在聊天中进行任何对话时,都会向其他聊天用户生成一封电子邮件。其他用户可以查看电子邮件,并且可以从同一封电子邮件回复到聊天对话中。我正在使用 angular 流星。我怎样才能实现这个功能? sendgrid 或 mailgun 中是否有任何 API 来处理来自电子邮件的呼叫并添加对话?或者我必须创建 POST/GET 方法来接受点击邮件中按钮的调用并保存回复文本?
您可以告诉 sendgrid 在收到传入电子邮件时对您的服务器执行 REST api 调用。
发送电子邮件时,将回复电子邮件设置为@chat-reply.myserver.com
然后您在服务器代码中设置一个端点来处理这些请求。您的代码将需要从传入地址查找对话,然后它可以在聊天中保存一条记录。
这是一些代码...
import { Meteor } from 'meteor/meteor'
formidable = require('formidable'); // Formidable does upload form/file parsing
import { Profiles } from '../imports/api/collections';
import { inboundReply } from '../imports/api/inbound/methods.js';
const debug = require('debug')('myapp:inbound')
// Needs to run on the server and client, why this is not in the routing.js file
// which is only only runs on the client.
// Inbound emails, for loop reply
//
// This is a RESTAPI end point which is called by sendgrid,
// any email to xxxx@chat-reply.myserver.com.au will come here. Our job
// is to parse it , work out which loop it relates to, and save it as a message
// in the database
//
Router.route('/inbound', function () {
// Need to use formidable because SendGrid inbound data is encoded as a multipart/form-data
const form = new formidable.IncomingForm();
// Meteor bind eviron. to get callback
debug(this.request.body)
let r = this.response
form.parse(this.request, Meteor.bindEnvironment(function (error, fields, files) {
if (error)
console.error(error);
let errs = []
// Gets the to field
const toField = _.find(fields, function(value, key) { if (key === 'to') { return value; }});
// Gets the from field
const fromField = _.find(fields, function(value, key) { if (key === 'from') { return value; }});
// Gets the html content, email
const content = _.find(fields, function(value, key) { if (key === 'text') { return value; }});
let cleanContent;
if (content){
// Logger.trace({content: content});
// Regex removes html
// cleanContent = content.replace(/<br>/ig, "\n");
// const regex = /(<([^>]+)>)/ig
// cleanContent = cleanContent.replace(regex, "");
// Logger.trace({cleanContent: cleanContent});
let lines = content.split(/\n/);
debug("Incoming body",lines);