ashik-gmail-sender
Version:
A simple and easy-to-use Node.js package to send emails through Gmail using Nodemailer. Send emails securely with Gmail's SMTP server, including text and HTML emails.
32 lines (27 loc) • 856 B
JavaScript
import nodemailer from 'nodemailer';
const sendEmail = (options) => {
// Create transporter using Gmail SMTP settings
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: options.user, // Your Gmail address (from)
pass: options.pass, // Your Gmail password or OAuth token
},
});
const mailOptions = {
from: options.user, // sender's email
to: options.to, // recipient's email
subject: options.subject, // subject of the email
text: options.text, // plain text body
html: options.html, // HTML body (optional)
};
// Send email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Error sending email:', error);
} else {
console.log('Email sent:', info.response);
}
});
};
export default sendEmail;