Email sending

Email sending

The template includes an integrated email sender. You can develop locally with a dummy provider and switch to a production provider like SendGrid when you go live.


Sending emails in local development (dev)

The Dummy provider is enabled by default. It is for local dev only and does not send emails. On initial sign up, the verification link is written to the server logs. Click that link to verify and continue.

main.wasp
app SaaSTemplate {
  // ...
  emailSender: {
    provider: Dummy,
    defaultFrom: {
      name: "Open SaaS App",
      email: "[email protected]"
    },
  },
⚠️

Important!

The app will not build for production while using Dummy. You must switch to a production provider before building.

Using a production provider (SendGrid)

Configure emailSender for SendGrid in main.wasp as shown. The defaultFrom.email must match the sender address configured in your SendGrid account.

main.wasp
app SaaSTemplate {
  // ...
  emailSender: {
    provider: SendGrid,
    defaultFrom: {
      name: "LaunchPike App",
      // When using SendGrid, you must use the same email address that you configured
      email: "[email protected]"
    },
  },

Sending an email from your server code

Use the Wasp emailSender.send function wherever you need it. Example below sends an email when Stripe signals a cancel at period end.

src/server/webhooks.ts
import { emailSender } from "wasp/server/email";

//…

if (subscription.cancel_at_period_end) { await emailSender.send({ to: customer.email, subject: ‘We hate to see you go :(’, text: ‘We hate to see you go. Here is a sweet offer…’, html: ‘We hate to see you go. Here is a sweet offer…’, }); }


Provider setup steps

SendGrid

  1. Create an account at SendGrid and generate your API key
  2. Add the key to .env.server as SENDGRID_API_KEY
  3. In main.wasp, set emailSender.provider = SendGrid and set defaultFrom.email to the same verified sender address you configured in SendGrid
main.wasp
emailSender: {
  provider: SendGrid,
  defaultFrom: {
    name: "LaunchPike App",
    email: "[email protected]" // <--- same email address you configured in SendGrid
  },

Mailgun

Create a Mailgun account, get your API credentials, and configure emailSender similarly using the Mailgun provider.

main.wasp
emailSender: {
  provider: Mailgun,
  defaultFrom: {
    name: "LaunchPike App", 
    email: "[email protected]" // <--- same email address you configured in Mailgun
  },

Thanks for trying this out — if it's useful, hit that GitHub star.