Solved

Can Shopify webhooks trigger an email notification for product sales?

nandezer
Tourist
12 2 8

Hey, 

I'm fairly new to Shopify Apps. I'm making a React & Node.js app where I'm adding my product to Online Stores and when the product is sold, I need to receive an email.

I already have the webhook establishment, product creation, checkbox to add the product into the cart, etc... So I already have a trigger when there is another with my product, what I can't seem to find is how to send an email from my Shopify app to my personal email letting me know my product has been sold.

From the little I found I need to connect my app to an email server but I can't find any documentation on how.

Can anyone provide any information on how I can receive when the sale is done?

 

P.S: Another method I looked at is if adding a vendor to the online store would notify such vendor (a.k.a me) with the sales directly through "normal" Shopify. But again, I haven't been able to find anything on this.

Accepted Solution (1)

ShanifAtApteo
Shopify Partner
35 3 5

This is an accepted solution.

Hi @nandezer, Happy to help you as you are using Node with React you can use Nodemailer for this you need to set up a mail server for this which will receive your object and trigger an email to the desired persons as you mentioned before we will start writing let's import our necessary packages we will use yarn add express nodemailer nodemon.

Now create an app.js file, where you will write all your code.

Now you will import packages to use here and create a SMTP protocol in order for Nodemailer to send mails. This protocol is used by email hosts such as gmail, hotmail etc.

let express = require('express');

let app = express();

const path = require('path');

let nodemailer = require('nodemailer');

 

// Static folder

app.use('/public', express.static(path.join(__dirname, 'public')));

nodemailer.createTransport({

  host: "mail.YOURDOMAIN.com",

port: 587,

secure: false,

  auth: {

user: "YOURUSERNAME",

pass: "YOURPASSWORD"

  }

});

router.post('/access', (req, res, next) => {

  var email = req.body.email

  var message = req.body.message

  var content = `email: ${email} \n message: ${message} `

  var mail = {

from: name,

to: name,

message: subject,

text: content

  }

  transporter.sendMail(mail, (err, data) => {

if (err) {

   res.json({

     status: 'fail'

   })

} else {

   res.json({

    status: 'success'

   })

}

  })

})

const PORT = process.env.PORT || 8080

app.listen(PORT, () => console.info(`server has started on ${PORT}`))

 

We tried to help with a simple example but you can tweak and make this much better if needed. Let me know if you have any questions, thanks!

Shanif Dhanani, CEO and data scientist at Apteo
- Was I able to help? Click Like to let me know!
- If I was able to answer your question, click Accept as Solution
- Want to increase your customer lifetime value with A.I.? Check out Apteo

View solution in original post

Reply 1 (1)

ShanifAtApteo
Shopify Partner
35 3 5

This is an accepted solution.

Hi @nandezer, Happy to help you as you are using Node with React you can use Nodemailer for this you need to set up a mail server for this which will receive your object and trigger an email to the desired persons as you mentioned before we will start writing let's import our necessary packages we will use yarn add express nodemailer nodemon.

Now create an app.js file, where you will write all your code.

Now you will import packages to use here and create a SMTP protocol in order for Nodemailer to send mails. This protocol is used by email hosts such as gmail, hotmail etc.

let express = require('express');

let app = express();

const path = require('path');

let nodemailer = require('nodemailer');

 

// Static folder

app.use('/public', express.static(path.join(__dirname, 'public')));

nodemailer.createTransport({

  host: "mail.YOURDOMAIN.com",

port: 587,

secure: false,

  auth: {

user: "YOURUSERNAME",

pass: "YOURPASSWORD"

  }

});

router.post('/access', (req, res, next) => {

  var email = req.body.email

  var message = req.body.message

  var content = `email: ${email} \n message: ${message} `

  var mail = {

from: name,

to: name,

message: subject,

text: content

  }

  transporter.sendMail(mail, (err, data) => {

if (err) {

   res.json({

     status: 'fail'

   })

} else {

   res.json({

    status: 'success'

   })

}

  })

})

const PORT = process.env.PORT || 8080

app.listen(PORT, () => console.info(`server has started on ${PORT}`))

 

We tried to help with a simple example but you can tweak and make this much better if needed. Let me know if you have any questions, thanks!

Shanif Dhanani, CEO and data scientist at Apteo
- Was I able to help? Click Like to let me know!
- If I was able to answer your question, click Accept as Solution
- Want to increase your customer lifetime value with A.I.? Check out Apteo