Send Email Skill
Overview
This skill allows you to send emails through an SMTP server. It handles authentication, attachment support, and error handling with proper logging.
Parameters
- to (string, required): Email address of the recipient
- subject (string, required): Email subject line
- body (string, required): Email body content (supports HTML)
- from (string, optional): Sender email address (defaults to configured address)
- attachments (array, optional): Array of file paths to attach
- cc (array, optional): CC recipients
- bcc (array, optional): BCC recipients
Returns
- success (boolean): Whether the email was sent successfully
- messageId (string): Unique message identifier for tracking
- timestamp (ISO 8601): When the email was sent
Examples
Basic Usage
const result = await emailSkill.send({
to: 'user@example.com',
subject: 'Hello!',
body: 'This is a test email.'
});
console.log(`Email sent with ID: ${result.messageId}`);
With Attachments
const result = await emailSkill.send({
to: 'user@example.com',
subject: 'Report',
body: 'Please find the report attached.',
attachments: ['/path/to/report.pdf']
});
Error Handling
try {
const result = await emailSkill.send({
to: 'invalid-email',
subject: 'Test',
body: 'Content'
});
} catch (error) {
if (error.code === 'INVALID_EMAIL') {
console.error('Invalid email address provided');
} else if (error.code === 'AUTH_FAILED') {
console.error('SMTP authentication failed - check credentials');
} else {
console.error(`Unexpected error: ${error.message}`);
}
}
Permissions Required
- email:send - Required to send emails
- filesystem:read - Required for accessing attachments
- credential:smtp - Requires SMTP server configuration
⚠️ Warning: This skill requires SMTP credentials to be configured securely. Never hardcode credentials in your skill definitions. Use environment variables or secure credential storage.
Error Handling
The skill can throw the following errors:
INVALID_EMAIL- Recipient email format is invalidAUTH_FAILED- SMTP authentication failedATTACHMENT_NOT_FOUND- Referenced attachment file doesn't existSIZE_LIMIT_EXCEEDED- Email size exceeds server limitsNETWORK_ERROR- Connection to SMTP server failed
All errors are logged with context and timestamps for debugging.
Input Validation
- Email addresses are validated against RFC 5322 standard
- Attachment paths are checked for existence and readability
- Email body size is limited to 25MB
- HTML content is sanitized to prevent injection attacks
Best Practices
- Always validate email addresses before sending
- Use try-catch blocks around email operations
- Store credentials securely - use env vars or secret management
- Implement rate limiting to prevent spam
- Log successful sends for audit trails
- Test with test@example.com before production use
Related Skills
- sendSMS - Send SMS messages
- sendSlack - Send Slack notifications
- sendWebhook - Send HTTP webhooks
Support
For issues or questions, see Email Skill Documentation