PocketStarter Docs

Email Sending

PocketStarter uses PocketBase's built-in mailer to send emails automatically. PocketBase includes a powerful email system that automatically handles:

  • Email verification - When users sign up
  • Password reset - When users forget their password

With PocketStarter, this functionality is extended to include contact form submissions, and you can also send any other custom emails as needed.

Enable mail settings

To set email up, go to your PocketBase backend and navigate to Dashboard → Settings → Mail settings. Enter your SMTP credentials.

Examples of providers you can use are:

Be sure to send a test email to confirm that your email settings are working correctly.

Contact Form Notifications

When someone submits the contact form, an email is sent to the admin:

// This happens automatically in the contact form hook
const message = new MailerMessage({
    from: {
        address: $app.settings().meta.senderAddress,
        name: $app.settings().meta.senderName,
    },
    to: [{ 
        address: $app.settings().meta.senderAddress // Admin email
    }],
    subject: `New Contact Form Submission from ${data.name}`,
    html: `
        <h2>New Contact Form Submission</h2>
        <p><strong>Name:</strong> ${data.name}</p>
        <p><strong>Email:</strong> ${data.email}</p>
        <p><strong>Message:</strong></p>
        <p>${data.message}</p>
    `
})

$app.newMailClient().send(message)

Change default emails

PocketBase has built-in functionality to customize the default email templates that are sent when users register, reset their password, or perform other account actions.

To customize these templates:

  1. Go to your PocketBase admin dashboard
  2. Navigate to Collectionsusers
  3. Click the Settings tab (gear icon)
  4. Under the Mail templates section, you can eit the templates for:
    • Verification email - Sent when users sign up
    • Password reset - Sent when users request password reset
    • Email change - Sent when users change their email address

You can customize both the subject line and email content using HTML formatting.

PocketBase Default Email Templates

The Mail templates section in PocketBase is where you can customize built-in email templates

Sending custom emails

One possibility is building marketing email flows using marketing tools (e.g. for automated email sequences, drip campaigns, and targeted marketing). See the marketing documentation for a sample integration with Brevo.

For more custom email needs, you can send emails directly from PocketBase hooks.

From PocketBase Hooks

// Example: Send welcome email when user is created
onRecordAfterCreateSuccess((e) => {
    const record = e.record;
    
    const message = new MailerMessage({
        from: {
            address: $app.settings().meta.senderAddress,
            name: $app.settings().meta.senderName,
        },
        to: [{ 
            address: record.get('email')
        }],
        subject: 'Welcome to PocketStarter!',
        html: `
            <h1>Welcome ${record.get('name')}!</h1>
            <p>Thanks for joining us.</p>
        `
    })
    
    $app.newMailClient().send(message)
    
    e.next();
}, 'users')