wildduck/imap-core/test/client.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-06-03 14:51:58 +08:00
/* eslint no-console:0 */
'use strict';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2017-07-16 19:37:33 +08:00
const config = require('wild-config');
const { ImapFlow } = require('imapflow');
2017-06-03 14:51:58 +08:00
const client = new ImapFlow({
host: '127.0.0.1',
port: config.imap.port,
secure: config.imap.secure,
2017-06-03 14:51:58 +08:00
auth: {
user: 'testuser',
pass: 'secretpass'
},
tls: {
rejectUnauthorized: false
},
clientInfo: {
name: 'My Client',
version: '0.1'
2017-06-03 14:51:58 +08:00
}
});
client.on('error', err => {
2017-06-03 14:51:58 +08:00
console.log(err);
process.exit(1);
});
2017-06-03 14:51:58 +08:00
const raw = Buffer.from('from: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\nzzzz\r\n');
client
.connect()
.then(() => client.append('INBOX', raw))
.then(() => client.mailboxOpen('INBOX'))
.then(mailbox => client.fetchOne(mailbox.exists, { bodyStructure: true, source: true }))
.then(data => {
console.log('<<<%s>>>', data.source.toString());
return process.exit(0);
})
.catch(err => {
console.log(err);
process.exit(1);
2017-06-03 14:51:58 +08:00
});