Send email from your app
Two kinds of email
Your project sends email in two ways:
- Authentication emails: verification, magic link, one-time code and password reset. You met these in the first lesson.
- Transactional mail: the email your own app sends, such as receipts and notifications.
You will polish the first and set up the second.
Make authentication emails yours
- Open Authentication > Settings > Emails.
- In Email, pick Email verification.
- Set a Sender name (up to 60 characters) and a Button colour like
#0f766e. It must be dark enough for white button text. - Edit the Subject and Message. Use Insert chips such as
{{project_name}},{{link_or_token}}and{{expires_in}}. A preview updates as you type. - Choose Email me this one to check it in a real inbox. The code or link in the test is a sample.
- Choose Save changes.
To send these emails from your own address, open Sender domain, enter a domain and a Send from name such as auth, then Add domain. Add the DNS records shown and choose Check DNS until it says Verified. If anything goes wrong, emails fall back to PGB's address so nobody is locked out. You can use up to five domains on your account.
Get approved for transactional mail
Because every project shares sending reputation, new projects need a short review.
- Open Transactional Mail in the sidebar.
- If prompted, describe what you will send under What will you use Transactional Mail for?, add your website and contact email, and choose Request Transactional Mail Access.
- Wait for approval. The page says Access request pending review. If more information is requested, answer under Submit Details & Resume Review.
Send your first email
Once approved, choose Send a Test Email, fill Recipient Email, Subject and Message Body, and Send Live Test Email. It appears in Email Event History & Delivery Logs.
From your server, with the secret key:
const sent = await admin.mail.send({
to: "[email protected]",
subject: "Your note was saved",
text: "We saved your note.",
html: "<p>We saved your note.</p>",
});
console.log(sent.message_id);
to takes one address, text is required, and reply_to takes a single address. Sends are not retried for you, so retry only when you know the first one did not go out.
Verify your own domain
Under Verify Your Own Domain, enter your domain and choose Add Domain. Add the Type, Name and Value records at your DNS provider, then Check Verification. When it is Verified, mail defaults to [email protected]. A from address on any other domain is replaced by the default sender.
Protect your reputation
The page shows Bounce Rate and Complaint Rate. Above 2.5% bounces or 0.08% complaints, your project is quarantined and sending stops. Only email people who expect it and stop emailing addresses that bounce. There is also a free monthly allowance and a per-minute limit. See Pricing for current rates.
Send email as part of a flow
Put an email at the end of a transaction with an action's mail effect, so it only goes out if the data was saved. Or add a Mail target to a cron job or an event rule.
Recap
- Customize authentication emails and optionally send them from your domain.
- Transactional mail needs approval, then one authenticated request per recipient.
- Verify a domain for your brand and better delivery.
- Watch bounce and complaint rates.
Open Access Course
Free
forever- 9 structured lessons across 6 modules
- Interactive knowledge checks with instant feedback
- Verifiable completion certificate & PDF