Nodemailer send email without smtp transport

前端 未结 7 1403
孤街浪徒
孤街浪徒 2021-02-01 19:47

I am trying to send emails via nodemailer without SMTP transport. So i\'ve done that:

var mail = require(\"nodemailer\").mail;

mail({
    from: \"Fred Foo ✔ <         


        
7条回答
  •  花落未央
    2021-02-01 20:03

    From your example output it seems to connecting to wrong port 25, gmail smtp ports which are opened are 465 for SSL and the other 587 TLS.

    Nodemailer detects the correct configuration based on the email domain, in your example you have not set the transporter object so it uses the default port 25 configured. To change the port specify in options the type.

    Here's the small example that should work with gmail:

    var nodemailer = require('nodemailer');
    
    // Create a SMTP transport object
    var transport = nodemailer.createTransport("SMTP", {
            service: 'Gmail',
            auth: {
                user: "test.nodemailer@gmail.com",
                pass: "Nodemailer123"
            }
        });
    
    console.log('SMTP Configured');
    
    // Message object
    var message = {
    
        // sender info
        from: 'Sender Name ',
    
        // Comma separated list of recipients
        to: '"Receiver Name" ',
    
        // Subject of the message
        subject: 'Nodemailer is unicode friendly ✔', 
    
        // plaintext body
        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 following line //transport.close(); // close the connection pool });

提交回复
热议问题