email-sending
Email sending integration. Covers Nodemailer (Node.js), Spring Mail (Java), smtplib (Python). Transactional email services: SendGrid, Amazon SES, Resend. Template engines: MJML, React Email. USE WHEN: user mentions "send email", "nodemailer", "SMTP", "SendGrid", "SES", "Resend", "transactional email", "email template", "MJML", "React Email", "spring mail" DO NOT USE FOR: push notifications - use `push-notifications`; SMS - different channel; email parsing/reading
What this skill does
# Email Sending
## Node.js (Nodemailer)
```typescript
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 587,
secure: false, // true for 465
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS },
});
await transporter.sendMail({
from: '"My App" <[email protected]>',
to: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome</h1><p>Thanks for signing up.</p>',
});
```
## Transactional Email Services
### Resend (recommended for simplicity)
```typescript
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
await resend.emails.send({
from: 'My App <[email protected]>',
to: ['[email protected]'],
subject: 'Welcome!',
html: '<h1>Welcome</h1>',
});
```
### SendGrid
```typescript
import sgMail from '@sendgrid/mail';
sgMail.setApiKey(process.env.SENDGRID_API_KEY!);
await sgMail.send({
to: '[email protected]',
from: '[email protected]',
templateId: 'd-abc123', // Dynamic template
dynamicTemplateData: { name: 'John', link: resetUrl },
});
```
### Amazon SES (via AWS SDK v3)
```typescript
import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
const ses = new SESv2Client({ region: 'us-east-1' });
await ses.send(new SendEmailCommand({
FromEmailAddress: '[email protected]',
Destination: { ToAddresses: ['[email protected]'] },
Content: {
Simple: {
Subject: { Data: 'Welcome!' },
Body: { Html: { Data: htmlContent } },
},
},
}));
```
## Email Templates
### React Email (recommended for React projects)
```tsx
// emails/welcome.tsx
import { Html, Head, Body, Container, Text, Button } from '@react-email/components';
export function WelcomeEmail({ name, url }: { name: string; url: string }) {
return (
<Html>
<Head />
<Body style={{ fontFamily: 'sans-serif' }}>
<Container>
<Text>Welcome, {name}!</Text>
<Button href={url} style={{ background: '#000', color: '#fff', padding: '12px 20px' }}>
Get Started
</Button>
</Container>
</Body>
</Html>
);
}
// Render to HTML string
import { render } from '@react-email/render';
const html = await render(<WelcomeEmail name="John" url="https://app.com" />);
```
### MJML (framework-agnostic)
```typescript
import mjml2html from 'mjml';
const { html } = mjml2html(`
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Welcome, {{name}}!</mj-text>
<mj-button href="{{url}}">Get Started</mj-button>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`);
```
## Python
```python
from email.message import EmailMessage
import aiosmtplib
msg = EmailMessage()
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg["Subject"] = "Welcome!"
msg.set_content("Welcome!", subtype="html")
await aiosmtplib.send(msg, hostname=SMTP_HOST, port=587,
username=SMTP_USER, password=SMTP_PASS, start_tls=True)
```
## Java (Spring Mail)
```java
@Service
public class EmailService {
@Autowired private JavaMailSender mailSender;
@Autowired private TemplateEngine templateEngine; // Thymeleaf
public void sendWelcome(String to, String name) {
var ctx = new Context();
ctx.setVariable("name", name);
String html = templateEngine.process("welcome", ctx);
var message = mailSender.createMimeMessage();
var helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setFrom("[email protected]");
helper.setSubject("Welcome!");
helper.setText(html, true);
mailSender.send(message);
}
}
```
## Anti-Patterns
| Anti-Pattern | Fix |
|--------------|-----|
| Sending email in request handler | Use background job queue (BullMQ, Celery) |
| No retry on transient failure | Retry with exponential backoff (3 attempts) |
| Hardcoded from address | Use env var, match verified domain |
| HTML without plain text fallback | Always include both HTML and text versions |
| No unsubscribe header | Add `List-Unsubscribe` header (required by Gmail/Yahoo) |
| Sending from unverified domain | Set up SPF, DKIM, DMARC records |
## Production Checklist
- [ ] SPF, DKIM, DMARC DNS records configured
- [ ] Domain verified with email provider
- [ ] `List-Unsubscribe` header on marketing emails
- [ ] Bounce and complaint handling (webhook)
- [ ] Email sending via background queue (not in request)
- [ ] Rate limiting to stay within provider limits
- [ ] Plain text fallback for all HTML emails
- [ ] Template preview/testing before deploy
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.