Email Automation
Send transactional emails and read mailboxes via SMTP/IMAP/POP3. Build email workflows without managing mail servers.
Quick Reference: All requests go to POST /api/services/execute with your API key in the Authorization: Bearer YOUR_API_KEY header.
Send Emails via SMTP
Service: email-access
Send emails via SMTP with HTML support and attachments. Works with any SMTP server including SendGrid, Mailgun, Gmail, and more.
Send Order Confirmation Email
Send a transactional email with HTML formatting when an order is placed.
// JavaScript - Send order confirmation
const response = await fetch('https://www.acrewity.com/api/services/execute', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
service: 'email-access',
operation: 'send_email',
parameters: {
smtp_host: 'smtp.sendgrid.net',
smtp_port: 587,
smtp_user: 'apikey',
smtp_pass: 'YOUR_SENDGRID_API_KEY',
from: 'orders@yourstore.com',
to: 'customer@example.com',
subject: 'Order Confirmed - #ORD-2024-5678',
html: `
<h1>Thank you for your order!</h1>
<p>Your order #ORD-2024-5678 has been confirmed.</p>
<p>Estimated delivery: January 18, 2025</p>
<a href="https://yourstore.com/track/ORD-2024-5678">Track your order</a>
`
}
})
});
Send Password Reset Email
Send a password reset link with a secure token.
# Python - Send password reset email
import requests
response = requests.post(
'https://www.acrewity.com/api/services/execute',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'service': 'email-access',
'operation': 'send_email',
'parameters': {
'smtp_host': 'smtp.mailgun.org',
'smtp_port': 587,
'smtp_user': 'postmaster@yourdomain.com',
'smtp_pass': 'YOUR_MAILGUN_PASSWORD',
'from': 'noreply@yourapp.com',
'to': user_email,
'subject': 'Reset Your Password',
'html': f'''
<h2>Password Reset Request</h2>
<p>Click the link below to reset your password:</p>
<a href="https://yourapp.com/reset?token={reset_token}">
Reset Password
</a>
<p>This link expires in 1 hour.</p>
'''
}
}
)
Send Email with Attachment
Include file attachments with your emails.
// JavaScript - Email with attachment
const pdfBase64 = await readFileAsBase64('invoice.pdf');
const response = await fetch('https://www.acrewity.com/api/services/execute', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
service: 'email-access',
operation: 'send_email',
parameters: {
smtp_host: 'smtp.sendgrid.net',
smtp_port: 587,
smtp_user: 'apikey',
smtp_pass: 'YOUR_SENDGRID_API_KEY',
from: 'billing@yourcompany.com',
to: 'client@example.com',
subject: 'Invoice #INV-2024-0892',
text: 'Please find your invoice attached.',
attachments: [
{
filename: 'invoice-2024-0892.pdf',
content: pdfBase64,
encoding: 'base64'
}
]
}
})
});
Use Cases:
Send password resets, order confirmations, and account notifications.
Send scheduled reports to stakeholders on a daily/weekly basis.
Send email alerts when monitors detect issues or thresholds are exceeded.
Automatically send welcome emails when new users sign up.
Read Emails via IMAP
Service: email-access
Read emails from any IMAP server. Monitor inboxes, parse incoming emails, and trigger workflows based on email content.
Monitor Support Inbox
Check for new support emails to trigger automated responses or alerts.
# Python - Check for new support emails
import requests
response = requests.post(
'https://www.acrewity.com/api/services/execute',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'service': 'email-access',
'operation': 'fetch_emails_imap',
'parameters': {
'imap_host': 'imap.gmail.com',
'imap_port': 993,
'imap_tls': True,
'imap_user': 'support@yourcompany.com',
'imap_pass': 'your-app-password',
'folder': 'INBOX',
'limit': 10
}
}
)
emails = response.json()['result']['data']['emails']
for email in emails:
print(f"From: {email['from']}")
print(f"Subject: {email['subject']}")
print(f"Date: {email['date']}")
print("---")
Parse Order Emails from Supplier
Extract order details from emails sent by a supplier system.
// JavaScript - Parse incoming emails
const response = await fetch('https://www.acrewity.com/api/services/execute', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
service: 'email-access',
operation: 'fetch_emails_imap',
parameters: {
imap_host: 'imap.yourcompany.com',
imap_port: 993,
imap_tls: true,
imap_user: 'orders@yourcompany.com',
imap_pass: 'your-password',
folder: 'Orders',
limit: 25
}
})
});
const { result } = await response.json();
const orderEmails = result.data.emails.filter(
email => email.from.includes('supplier.com')
);
// Process each order email
for (const email of orderEmails) {
const orderData = parseOrderFromEmail(email.text);
await processOrder(orderData);
}
Use Cases:
Read and parse incoming emails to trigger workflows or extract data.
Monitor support inbox and auto-create tickets from incoming emails.
Read Emails via POP3
Service: email-access
Alternative to IMAP for servers that only support POP3. Downloads messages from the server.
Fetch Latest Messages
Retrieve recent emails from a POP3 server.
curl -X POST https://www.acrewity.com/api/services/execute \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"service": "email-access",
"operation": "fetch_emails_pop3",
"parameters": {
"pop3_host": "pop.yourserver.com",
"pop3_port": 995,
"pop3_tls": true,
"pop3_user": "inbox@yourcompany.com",
"pop3_pass": "your-password",
"limit": 5
}
}'
Best Practices
Use App Passwords
For Gmail and other providers with 2FA, generate an app-specific password:
- Gmail: Security → 2-Step Verification → App passwords
- Outlook: Security → App passwords
Store Credentials Securely
Never hardcode SMTP credentials. Use environment variables or a secrets manager:
// Good - Use environment variables
const smtpConfig = {
smtp_host: process.env.SMTP_HOST,
smtp_port: parseInt(process.env.SMTP_PORT),
smtp_user: process.env.SMTP_USER,
smtp_pass: process.env.SMTP_PASS
};
Handle Errors
Check for delivery failures and log appropriately:
const response = await fetch('https://www.acrewity.com/api/services/execute', { ... });
const data = await response.json();
if (!data.success) {
console.error('Email failed:', data.error);
// Queue for retry or alert admin
}
Related Services
- Email Access - Full service documentation