((我为我的英语不好而感到抱歉,但我会尽力而为!):)
我正在尝试为个人项目设置本地邮箱,并且我正在尝试使用imap-simple和nodemailer来做到这一点。
我希望在发送电子邮件时能够识别线程。
这是我真正想要做的:
在我的应用程序中,我将能够向特定的人发送电子邮件(让我们承认[email protected])
[发送邮件时,回调函数将邮件内容和主题存储在DB中(例如,在CRM应用中,我将与数据库中的特定记录相关的已发送邮件存储在数据库中。]
复杂的部分就在那之后:
[当该人回复此电子邮件时,我想使用IMAP识别此人正在回答我以前的邮件,然后也将其存储在DB中,也链接到我在第一封电子邮件中使用的相同记录。
我实际上在沙盒文件夹中有此文件(对于IMAP:):>
var imaps = require('imap-simple'); var nodemailer = require('nodemailer'); var config = { imap: { user: '[email protected]', password: 'xxxxxxxx', host: 'imap.gmail.com', port: 993, tls: true, authTimeout: 3000 } }; imaps.connect(config).then(function (connection) { return connection.openBox('INBOX').then(function () { var searchCriteria = [ 'UNSEEN' ]; var fetchOptions = { bodies: ['HEADER', 'TEXT'], markSeen: false, }; console.log('Passing there'); return connection.search(searchCriteria, fetchOptions).then(function (results) { var subjects = results.map(function (res) { return res.parts.filter(function (part) { return part.which === 'HEADER'; })[0].body.subject[0]; }); console.log('BASE'); console.log(results[0]); console.log('FIRST'); console.log(results[0].parts[0]); console.log('SECOND'); console.log(results[0].parts[1]); }); }); });
这是SMTP部分:
var transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: '[email protected]', pass: 'xxxxxxxx' } }); const mailOptions = { from: '[email protected]', // sender address to: '[email protected]', // list of receivers subject: 'Subject of your email', // Subject line html: '<p>Here is my test !</p>',// plain text body headers: { 'collection': 'Pipelines', 'doc-ID': 'mydocid' } }; transporter.verify(function(error, success) { if (error) { console.log(error); } else { console.log("Server is ready to take our messages"); } }); transporter.sendMail(mailOptions, function (err, info) { if(err) console.log(err) else console.log(info); });
这里是我想要的屏幕:
在IMAP
上,我正在控制台中获取我想要的确切信息:允许我标识一个线程。也许,我在nodemailer回调函数中找不到此信息:BASE { attributes: { date: 2019-12-05T16:53:07.000Z, flags: [], uid: 94, modseq: '27800', 'x-gm-labels': [ '\\Important' ], 'x-gm-msgid': '1652099423356172171', 'x-gm-thrid': '1652099362185438260' },
x-gm-thrid
Server is ready to take our messages { accepted: [ '[email protected]' ], rejected: [], envelopeTime: 400, messageTime: 819, messageSize: 346, response: '250 2.0.0 OK 1575566223 m3sm12955793wrs.53 - gsmtp', envelope: { from: '[email protected]', to: [ '[email protected]' ] }, messageId: '<[email protected]>' }
有人知道我该如何进行吗?
非常感谢!
快乐编码:)
((我为我的英语不好而感到抱歉,但我会尽力而为!):)我正在尝试为个人项目设置本地邮箱,并且我正在尝试使用imap-simple和nodemailer来做那。我想成为...
对于那些将阅读这篇文章的人,这里的答案,感谢@arnt,