nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 146 forks source link

Emit events instead of registering callbacks at construction time #111

Closed strugee closed 6 years ago

strugee commented 6 years ago

I'm very confused as to how this module is supposed to work. It seems like instances of SMTPServer are EventEmitters, but the events that it emits aren't documented? AFAICT you're supposed to pass callbacks at construction time but this really does not work great because sometimes you want to register listeners later (this is my use case because of the way my test suite is set up) or you want to use emitter.once instead of emitter.on. The current design is super confusing and inconsistent because there are a couple events you can listen for, but AFAICT most things have to be done with the on* options passed to the server constructor.

Let me know if I'm missing something obvious.

strugee commented 6 years ago

And thanks for maintaining NodeMailer, btw <3

andris9 commented 6 years ago

The "event" part of SMTPServer includes informational events like 'connect' etc. The callbacks you need to register are not informational but transactional and thus can't be really treated the same way events are treated. You are supposed to call your own handlers from the callback and return the result of the operation. You can see here a real-life example of setting up the callbacks