2017-07-25 125 views
0

我使用feathersjs構建了一個API,並且需要發送附件的電子郵件。Nodemailer - 電子郵件發送但沒有收到

該電子郵件似乎是發送,但我什麼都沒收到。

在我mail.service.js

const nodemailer = require('nodemailer'); 
const transporter = nodemailer.createTransport({ 
    host: 'smtp.office365.com', 
    port: 587, 
    secure: false, // secure:true for port 465, secure:false for port 587 
    auth: { 
    user: '[email protected]', 
    pass: 'MyPassWord' 
    } 
}); 

// Check the connection to the service. 
transporter.verify(function(error, success) { 
    if (error) { 
    console.log(error); 
    } else { 
    console.log('Server is ready to take our messages'); 
    } 
}); 

然後在我的鉤

hook => { 
    const file = hook.params.file; 

    const email = { 
     from: '[email protected]', // sender address 
     to: '[email protected]', // list of receivers 
     subject: 'Test Nodemailer', // Subject line 
     // text: req.body.text, // plaintext body 
     html: '<b>Hello world </b>', // html body 
     attachments: [ 
     { 
      filename: file.originalname, 
      contents: new Buffer(file.buffer, 'base64'), 
      encoding: 'base64' 
     } 
     ] 
    }; 

    return hook.app.service('mail').create(email) 
     .then(function (result) { 
     console.log('Sent email', result); 
     }).catch(err => { 
     console.log(err); 
     }); 
    } 

後來我

服務器準備採取我們的信息

發電子郵件

對象{來自: 「[email protected]」,到: 「[email protected]」,主題: 「測試Nodemailer」,HTML: 「世界,你好」}

我不知道如何檢查問題的來源。

回答

0

好吧,我知道了!

我需要添加transporter.sendMail()mail.class.js裏面,當我打電話hook.app.service('mail').create(email)

工作和attachement文件爲0字節的郵件,但我的變量中良好的尺寸來觸發這個動作。

相關問題