init email docs

This commit is contained in:
Madison 2025-08-18 15:00:15 -05:00
parent d4b943dc91
commit dc15780377
2 changed files with 35 additions and 51 deletions

View File

@ -63,15 +63,10 @@ type SendEmailOptions = {
themeId?: string | null | false; // Theme to apply (optional)
subject?: string; // Email subject
notificationCategoryName?: string; // Notification category for user preferences
} & (
| {
html: string; // Custom HTML content
}
| {
templateId: string; // Template ID to use
variables?: Record<string, any>; // Template variables
}
);
html?: string; // Custom HTML content
templateId?: string; // Template ID to use
variables?: Record<string, any>; // Template variables
};
```
### Error Handling
@ -116,37 +111,31 @@ These templates can be customized through the admin interface or programmaticall
## Email Configuration
Email configuration is managed through the Stack Auth dashboard or admin API, not directly in your application code. You have two options:
### Shared Email Provider (Development)
For development, you can use Stack's shared email provider:
For development and testing, you can use Stack's shared email provider. This sends emails from `noreply@stackframe.co` and is configured through your project settings in the Stack Auth dashboard.
```typescript
// In your project configuration
{
emailConfig: {
type: 'shared', // Uses Stack's shared email service
}
}
```
- Go to your project's Email settings in the dashboard
- Select "Shared" as your email server type
- No additional configuration required
### Custom Email Server (Production)
For production, configure your own email server:
For production, configure your own SMTP server through the dashboard:
```typescript
// In your project configuration
{
emailConfig: {
type: 'standard',
host: 'smtp.yourprovider.com',
port: 587,
username: 'your-username',
password: 'your-password',
senderEmail: 'noreply@yourdomain.com',
senderName: 'Your App Name',
}
}
```
- Go to your project's Email settings in the dashboard
- Select "Custom SMTP server" as your email server type
- Configure the following settings:
- **Host**: Your SMTP server hostname (e.g., `smtp.yourprovider.com`)
- **Port**: SMTP port (typically 587 for TLS or 465 for SSL)
- **Username**: Your SMTP username
- **Password**: Your SMTP password
- **Sender Email**: The email address emails will be sent from
- **Sender Name**: The display name for your emails
The dashboard will automatically test your configuration when you save it.
## Notification Categories
@ -178,7 +167,7 @@ For custom email flows, use the `sendEmail` method from your server-side code:
```typescript
// In your API route or server action
import { stackServerApp } from './stack';
import { stackServerApp } from '@stackframe/stack';;
export async function inviteUser(email: string) {
const result = await stackServerApp.sendEmail({

View File

@ -17,19 +17,14 @@ Options for sending emails via the `sendEmail` method on `StackServerApp`.
### Table of Contents
<ClickableTableOfContents code={`type SendEmailOptions = {
userIds: string[]; //$stack-link-to:#sendemaildoptionsuserids
themeId?: string | null | false; //$stack-link-to:#sendemaildoptionsthemeid
subject?: string; //$stack-link-to:#sendemaildoptionssubject
notificationCategoryName?: string; //$stack-link-to:#sendemaildoptionsnotificationcategoryname
} & (
| {
html: string; //$stack-link-to:#sendemaildoptionshtml
}
| {
templateId: string; //$stack-link-to:#sendemaildoptionstemplateid
variables?: Record<string, any>; //$stack-link-to:#sendemaildoptionsvariables
}
);`} />
userIds: string[]; //$stack-link-to:#sendemailoptionsuserids
themeId?: string | null | false; //$stack-link-to:#sendemailoptionsthemeid
subject?: string; //$stack-link-to:#sendemailoptionssubject
notificationCategoryName?: string; //$stack-link-to:#sendemailoptionsnotificationcategoryname
html?: string; //$stack-link-to:#sendemailoptionshtml
templateId?: string; //$stack-link-to:#sendemailoptionstemplateid
variables?: Record<string, any>; //$stack-link-to:#sendemailoptionsvariables
};`} />
<CollapsibleTypesSection type="sendEmailOptions" property="userIds" defaultOpen={false}>
<MethodLayout>
@ -130,12 +125,12 @@ Options for sending emails via the `sendEmail` method on `StackServerApp`.
<CollapsibleTypesSection type="sendEmailOptions" property="html" defaultOpen={false}>
<MethodLayout>
<MethodContent>
Custom HTML content for the email. Use this option when you want to send a custom HTML email instead of using a template.
Custom HTML content for the email. Use this option when you want to send a custom HTML email instead of using a template. Cannot be used together with `templateId` or `variables`.
</MethodContent>
<MethodAside>
<AsideSection title="Type">
```typescript
html: string
html?: string
```
</AsideSection>
<AsideSection title="Example">
@ -154,12 +149,12 @@ Options for sending emails via the `sendEmail` method on `StackServerApp`.
<CollapsibleTypesSection type="sendEmailOptions" property="templateId" defaultOpen={false}>
<MethodLayout>
<MethodContent>
ID of the email template to use. Use this option when you want to send a template-based email with variables.
ID of the email template to use. Use this option when you want to send a template-based email with variables. Cannot be used together with `html`.
</MethodContent>
<MethodAside>
<AsideSection title="Type">
```typescript
templateId: string
templateId?: string
```
</AsideSection>
<AsideSection title="Example">