Appearance
Sendgrid Email Provider
To use Sendgrid as your email provider, you need to create an account and obtain your API Key.
Then copy your API key and add it to the .env
file
SENDGRID_API_KEY='your-sendgrid-api-key'
The code for Sendgrid is found in server/_/mail/poviders/sendgrid.ts
ts
import sendgrid from '@sendgrid/mail'
import type {
SendEmailHandler,
SendEmailParams,
SendEmailWithHtml,
SendEmailWithText,
} from '~/server/_/mail/types'
const config = useRuntimeConfig()
console.log(config.sendgridApiKey)
sendgrid.setApiKey(config.sendgridApiKey)
export const send: SendEmailHandler = async (params: SendEmailParams) => {
const { subject, recipient: to } = params
// Type assertion to safely access html and text properties
const html = (params as SendEmailWithHtml).html
const text = (params as SendEmailWithText).text
await sendgrid.send({
from: config.emailSenderAddress,
to,
subject,
html,
text,
})
}
For more information, pleasw refer to the Sendgrid docs