Hello guys, I am trying to use mailgun webhooks
This is my server code main.js
import { Meteor } from 'meteor/meteor'
import { Accounts } from 'meteor/accounts-base'
import { Emails } from '../imports/collections/emails/Emails'
import { WebApp } from 'meteor/webapp'
import ConnectRoute from 'connect-route'
Meteor.startup(() => {
// code to run on server at startup
process.env.MAIL_URL = 'smtp://postmaster%40backtocart.co:0d1af42a4928eb3dd1b111643aa9088a@smtp.mailgun.org:587'
Accounts.emailTemplates.from = 'backtocart <info@backtocart.co>'
Meteor.publish('emails', function() {
return Emails.find({})
})
})
function onRoute (req, res, next) {
// 5p14i is for clicks
// aif6r is for opens
console.log('req', req)
// const { token } = req.params
// if (token === '5p14i') {
// console.log('clicks')
// } else if (token === 'aif6r') {
// console.log('opens')
// }
// next()
var rawPostBody = ''
var postData = []
req.on('data', function (chunk) {
console.log('on data')
rawPostBody += chunk.toString()
})
req.on('end', function () {
console.log('on end')
pairs = rawPostBody.split('&')
for(var i = 0; i < pairs.length; i++) {
kv = pairs[i].split('=')
postData[kv[0]]=decodeURIComponent((kv[1] + '').replace(/\+/g, '%20'))
console.log('postData', postData)
}})
console.log('next is called after I log')
next()
}
const middleware = ConnectRoute(function (router) {
// 2uik9 is for webhooks requests
router.post('/2uik9/:token', onRoute)
})
WebApp.connectHandlers.use(middleware)
I have this link https://b2c.meteorapp.com/2uik9/aif6r set as email opens’ tracking webhook.
When I set it as webhook and click test webhook in the mailgun, everything seems to work great. The webhook gets response and on my servers I can see the request logged. However when I send an actual email and open it no request is sent to that link. However I can see the tracking pixel inserted in the mail.
Can you help me with this? At least please tell me what do you think is everything done correct programmatically?
Thank you.