npm install reshuffle-smtp-connector
NPM Package: reshuffle-smtp-connector
This package is a Reshuffle connector that allows a developer to configure a transport that sends emails via SMTP.
The following code creates an HTTP endpoint at /ping
. Sending a GET
request to this endpoint with the following pattern,
sends an email to the address in the to
query parameter.
const { HttpConnector, Reshuffle } = require('reshuffle')
const { SMTPConnector } = require('reshuffle-smtp-connector')
const app = new Reshuffle()
const httpConnector = new HttpConnector(app)
const smtpConnector = new SMTPConnector(
app,
{
username: 'superman',
password: 'hunter123',
host: 'email.some.com',
port: 587,
fromName: 'Spiderman III',
fromEmail: '[email protected]',
},
'connectors/smtp',
)
httpConnector.on(
{
method: 'GET',
path: '/ping',
},
(event, app) => {
app.getConnector('connectors/smtp').send({
to: event.req.query.to,
subject: 'Ping Email',
html: 'You have been pinged',
})
},
)
app.start()
Hitting /[email protected]
will send a ping email to [email protected]
interface SMTPConnectorOptions {
fromName: string // The sender name to appear on outgoing emails
fromEmail: string // The sender email address to appear on outgoing emails
host: string // SMTP host
port: number // Port number for the host. Normally 587
username: string // Username to login to the SMTP host
password?: string // Password to login to the SMTP host
}
The SMTP connector provides the following actions:
Send an email message defined by the message parameter. SMTPConnector.send(message: EmailMessage) The EmailMessage type expects the following:
interface EmailMessage {
to: string | string[] // Recipient email address(es)
subject: string // Message subject
html: string // message content
attachments?: Attachment[]
}
The to
field can have the following formats:
- A single email address inside a string object
- A comma-separated list of email addresses inside a single string object
- An array of email addresses (strings)
Example on how to use this connector can be found here.