Sending email from local host with Nodemailer

前端 未结 5 1255
小蘑菇
小蘑菇 2020-12-20 13:38

I\'d like to send mails on my local server but it seems not working with Nodemailer and NodeJS.

Is there any solutions to send mails from local?

             


        
5条回答
  •  遥遥无期
    2020-12-20 14:29

    var nodemailer = require('nodemailer');
    
    // Create a SMTP transport object
    var transport = nodemailer.createTransport("SMTP", {
        service: 'Hotmail',
        auth: {
            user: "username",
            pass: "password"
        }
    });
    
    // Message object
    var message = {
    
    // sender info
    from: 'name@hotmail.com',
    
    // Comma separated list of recipients
    to: req.query.to,
    
    // Subject of the message
    subject:req.query.subject, //'Nodemailer is unicode friendly ✔', 
    
    // plaintext body
    text: req.query.text //'Hello to myself!',
    
     // HTML body
      /*  html:'

    Hello to myself

    '+ '

    Here\'s a nyan cat for you as an embedded attachment:

    '*/ }; console.log('Sending Mail'); transport.sendMail(message, function(error){ if(error){ console.log('Error occured'); console.log(error.message); return; } console.log('Message sent successfully!'); // if you don't want to use this transport object anymore, uncomment //transport.close(); // close the connection pool });

    You must specify the transport protocol like that of SMTP or create youy own transport.You have not specified this in you code.  

提交回复
热议问题