How to Send Email using Mailgun API in Node.js ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Sending an email is an essential part of any project and it can be achieved by using Mailgun API. It is very popular for sending emails. Features of Mailgun: . It is easy to get started and easy to use.It is a widely used and popular module for sending emails.Mails can also be scheduled. Installation of Mailgun module: You can visit the link to Install mailgun module. You can install this package by using the following command. npm install mailgun-js After installing mailgun you can check your mailgun version in the command prompt using the command. npm version mailgun-js After that, you can create a folder and add a file. For example index.js. To run this file you need to run the following command. node index.js Requiring module: You need to include mailgun module in your file by using these lines. const mailgun = require('mailgun-js'); Project Structure: Filename: index.js javascript let API_KEY = 'Your_Api_Key'; let DOMAIN = 'Your_Domain'; const mailgun = require('mailgun-js') ({ apiKey: API_KEY, domain: DOMAIN }); sendMail = function (sender_email, receiver_email, email_subject, email_body) { const data = { "from": sender_email, "to": receiver_email, "subject": email_subject, "text": email_body }; mailgun.messages().send(data, (error, body) => { if (error) console.log(error) else console.log(body); }); } let sender_email = '[email protected]' let receiver_email = '[email protected]' let email_subject = 'Mailgun Demo' let email_body = 'Greetings from geeksforgeeks' // User-defined function to send email sendMail(sender_email, receiver_email, email_subject, email_body) Steps to run the program: Make sure you have installed mailgun using the following commands: npm install mailgun-js Run the index.js file using the following command: node index.js If no error occurs, then go and check the receiver's email inbox Comment More infoAdvertise with us Next Article How to Send Email using Mailgun API in Node.js ? G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies Node.js Write From Home Node.js-Misc +1 More Similar Reads How to Send Email using NodeJS? Sending emails programmatically is a common requirement in many applications, especially for user notifications, order confirmations, password resets, and newsletters. In this article, we will learn how to build a simple email-sending system using NodeJS. We will use Nodemailer, a popular module for 5 min read How to send Attachments and Email using nodemailer in Node.js ? For this purpose, we will use a package called nodemailer. It is a module that makes email sending pretty easy. For using it, you will need to install by using the following command: $ npm install nodemailer Features of nodemailer module: It has zero dependencies and heavy security.You can use it 2 min read Sending bulk emails in Node.js using SendGrid API What is SendGrid API? SendGrid is a platform for sending transactional and marketing emails to the customers. It provides scalability, reliability, and deliverability which is an important issue for an organization.Benefits of using SendGrid API: If you are using Nodemailer with Gmail then you can s 2 min read How to send email with Nodemailer using Gmail account in Node ? Nodemailer is an npm module that allows you to send emails easily from the backend. In this article, we will cover the steps to send email using a Gmail account with the help of nodemailer. Prerequisites:NPM and NodeJSExpressJSApproach To send email with Nodemailer using gmailImport the nodemailer m 3 min read How to Send JSON Response using Node.js ? NodeJS is the runtime environment, which can execute the javascript code on any platform. It is widely used to create and run web application servers because of its salient features.During production, several times we need to send the resources or some type of information as a response, and javascri 5 min read Like