xpepermint / smtp-client

Simple, promisified, protocol-based SMTP client for Node.js.
36 stars 13 forks source link

cannot re-connect after quit #3

Closed soonoo27 closed 4 years ago

soonoo27 commented 6 years ago
let s = new SMTPClient({
  host: 'mx.server.com',
  port: 25,
});

await s.connect();
await s.quit();
await s.connect();
(node:31963) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'charAt' of undefined
    at connect.then (/Users/soonoo/dev/ad4th/newsletter-email-verifier/node_modules/smtp-client/src/index.js:29:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:31963) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31963) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is there anything wrong with my approach?

ndunks commented 5 years ago

If you want to send multiple email, just don't close/quit the conection.

await s.connect();
await s.greet({hostname: 'localhost'}); // runs EHLO command or HELO as a fallback
await s.authPlain({username: '*****', password: '*****'}); // authenticates a user
await s.mail({from: '*****@gmail.com'}); // runs MAIL FROM command
await s.rcpt({to: '*****@gmail.com'}); // runs RCPT TO command (run this multiple times to add more recii) 
await s.data('Subject: The Next Meeting\r\n\r\nmail source'); // runs DATA command and streams email source
// Second email
await s.mail({from: '*****@gmail.com'}); // runs MAIL FROM command
await s.rcpt({to: '*****@gmail.com'}); // runs RCPT TO command (run this multiple times to add more recii)
await s.data('mail source'); // runs DATA command and streams email source
await s.quit(); // runs QUIT command
ghost commented 5 years ago

or reconstruct the client if you need to send again after a while.