mailchan
v1.0.0
Published
Simple and flexible SMTP email sender with dry-run support for testing.
Maintainers
Readme
mailchan
Canonical URL:
https://alexstevovich.com/a/mailchan-nodejs
Software URL:
https://midnightcitylights.com/software/mailchan-nodejs
A simple and flexible SMTP email sender built on Nodemailer. MailChan allows for sending emails with SMTP credentials and also features dry-run mode for logging email activity without sending them.
Installation
npm install mailchanExample
import { MailChan } from 'mailchan';
const mail = new MailChan('gmail', '[email protected]', 'your-password');
// Send an email
mail.send('[email protected]', 'Test Subject', 'This is a test email.')
.then((response) => {
console.log('Email sent:', response);
})
.catch((error) => {
console.error('Error sending email:', error);
});
// Enable dry-run mode (no email will be sent, but it will be logged to console)
mail.dryRun(true);
// Test SMTP connection
mail.verify()
.then(() => console.log('SMTP connection verified successfully'))
.catch((error) => console.error('SMTP verification failed:', error));API
MailChan(service, user, pass, options)
Constructor
Creates an instance of the MailChan class with SMTP configuration.
Parameters:
service(string): The SMTP service (e.g., "gmail").user(string): SMTP username (typically your email address).pass(string): SMTP password or app-specific token.options(object, optional):dryRun(boolean, optional): Iftrue, the emails are not sent but logged to the console (default isfalse).
verify(options)
Method
Verifies the SMTP connection and credentials.
Parameters:
options.throw(boolean, optional): Iftrue, an error will be thrown on failure (default isfalse).
send(to, subject, text, fromOverride)
Method
Sends a plain-text email.
Parameters:
to(string | string[]): The recipient(s) of the email.subject(string): The subject of the email.text(string): The plain-text content of the email.fromOverride(string, optional): Optional custom "from" address. If not provided, theuserpassed to the constructor is used.
dryRun(enable)
Method
Toggles dry-run mode.
Parameters:
enable(boolean): Iftrue, emails will only be logged, not actually sent (default istrue).
License
Licensed under the Apache License 2.0.
