Skip to content
Snippets Groups Projects
Select Git revision
  • d26473c57b3e84f441688cfe26469cef1a3f9216
  • master default protected
2 results

mail.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    mail.js 990 B
    import nodemailer from "nodemailer";
    
    const transporter = nodemailer.createTransport({
    	host: process.env.MAIL_HOST,
    	port: parseInt(process.env.MAIL_PORT),
    	auth: {
    		user: process.env.MAIL_USER,
    		pass: process.env.MAIL_PASSWORD
    	},
    	secure: process.env.MAIL_TLS === "true",
    	authMethod: process.env.MAIL_AUTH_METHOD
    });
    
    /**
     * @param {Object} mailOptions
     * @param {string} mailOptions.to The email address to send the email to
     * @param {string} mailOptions.subject The subject of the email
     * @param {string} mailOptions.text The content of the email
     * @param {boolean} [mailOptions.html=false] `true` if `text` is HTML, `false` if `text` is plain text
     * @returns 
     */
    export async function sendMail({to, subject, text, html=false}) {
    	const content = html ? {html: text} : {text};
    	return transporter.sendMail({
    		subject,
    		to,
    		from: {
    			address: process.env.MAIL_FROM_ADDRESS,
    			name: process.env.MAIL_FROM_NAME
    		},
    		replyTo: process.env.MAIL_REPLY_TO,
    		...content
    	});
    }