Transactional Email

Sending an Email

Use this example to send a transactional email through Leadpush SMTP from your application.

This page shows simple SMTP examples you can use after your workspace is set up. It includes a Node.js example with nodemailer and a swaks example for quick command-line SMTP verification.

Before you send

Make sure all of these are already true:

  • your sending domain is verified
  • the exact from address has completed sender verification
  • you created an SMTP credential in the workspace
  • you know the SMTP host: smtp.leadpush.net
  • you know the SMTP port: 587

If any of those are not ready yet, start with:

Example environment variables

Store the SMTP settings and sender details in environment variables so you can keep the credential out of source control.

Example .env
LEADPUSH_SMTP_HOST=smtp.leadpush.net
LEADPUSH_SMTP_PORT=587
LEADPUSH_SMTP_USERNAME=your-generated-username
LEADPUSH_SMTP_PASSWORD=your-generated-password
LEADPUSH_SMTP_FROM=alerts@example.com

Example using Node.js and Nodemailer

Install nodemailer, then send a test email with the verified sender address from your workspace.

send-email.ts
import nodemailer from 'nodemailer'

const transporter = nodemailer.createTransport({
  host: process.env.LEADPUSH_SMTP_HOST || 'smtp.leadpush.net',
  port: Number(process.env.LEADPUSH_SMTP_PORT || 587),
  secure: false,
  auth: {
    user: process.env.LEADPUSH_SMTP_USERNAME,
    pass: process.env.LEADPUSH_SMTP_PASSWORD,
  },
})

async function main() {
  const info = await transporter.sendMail({
    from: process.env.LEADPUSH_SMTP_FROM || 'alerts@example.com',
    to: 'customer@example.com',
    subject: 'Your password reset link',
    text: 'Use this link to reset your password: https://example.com/reset',
    html: `
      <p>Use this link to reset your password:</p>
      <p><a href="https://example.com/reset">Reset password</a></p>
    `,
  })

  console.log('Message queued:', info.messageId)
}

main().catch((error) => {
  console.error('Failed to send email', error)
  process.exit(1)
})

Example using swaks

Use swaks when you want to verify SMTP authentication and message acceptance from the command line before wiring the same settings into your application.

swaks
swaks \
  --server smtp.leadpush.net \
  --port 587 \
  --tls \
  --auth LOGIN \
  --auth-user "$LEADPUSH_SMTP_USERNAME" \
  --auth-password "$LEADPUSH_SMTP_PASSWORD" \
  --from "$LEADPUSH_SMTP_FROM" \
  --to "customer@example.com" \
  --header "Subject: Your password reset link" \
  --body "Use this link to reset your password: https://example.com/reset"

What to replace in the example

Update these values before using the sample in a real application:

  • replace your-generated-username and your-generated-password with the SMTP credential from your workspace
  • replace alerts@example.com with a verified sender address from your workspace
  • replace customer@example.com with a real test recipient
  • replace the subject and body with the transactional message your app needs to send
  • if you use swaks, make sure the shell environment contains the same SMTP username, password, and from address values

What a successful test should prove

A good first test should confirm that:

  • your application can authenticate with the SMTP credential
  • the message is accepted using smtp.leadpush.net on port 587
  • the verified sender address appears correctly in the recipient inbox
  • the recipient receives the email generated by the same code path you plan to use in production

Troubleshooting