在SuperStarter中使用SendGrid

1

创建SendGrid账户

创建SendGrid账户并获取API密钥。

2

添加环境变量

SENDGIRD_TOKEN环境变量添加到您的.env.local文件以及部署环境中:

然后,确保激活SendGrid:

/packages/email/index.ts
export * from './providers/sendgrid';
3

发送邮件

apps/web/app/contact/actions/contact.tsx
import { sendgridClient } from '@repo/email';
import { ContactTemplate } from '@repo/email/emails/contact';
import { render } from "@react-email/components";

const emailHtml = await render(<ContactTemplate name={name} email={email} message={message} />);

await sendgridClient.send({
    from: 'sender@acme.com',
    to: 'recipient@acme.com',
    subject: '邮件主题',
    react: emailHtml,
});