Prompt
send email from app api
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
To send email from an app via an API, you generally use an email service provider’s HTTP API rather than connecting directly to an SMTP server.
Common options
- SendGrid
- Mailgun
- Amazon SES
- Postmark
- Resend
Basic flow
- Sign up with an email API provider.
- Verify your domain or sender email.
- Get an API key.
- Your app makes an HTTP request to the provider’s API.
- The provider sends the email.
Example: send email with a REST API
JavaScript / Node.js
const fetch = require('node-fetch');
async function sendEmail() {
const res = await fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
headers: {
'Authorization': `Bearer YOUR_API_KEY`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
personalizations: [{ to: [{ email: 'to@example.com' }] }],
from: { email: 'you@yourdomain.com' },
subject: 'Hello from my app',
content: [{ type: 'text/plain', value: 'This is a test email.' }]
})
});
console.log(res.status);
}
sendEmail();
Example: using SMTP from your app
If your API provider gives SMTP credentials, you can also send emails through SMTP libraries like:
- Node.js:
nodemailer - Python:
smtpliboryagmail - PHP:
PHPMailer
Important tips
- Never expose your email API key in frontend code.
- Use a backend server or serverless function.
- Add SPF, DKIM, and DMARC for better deliverability.
- Handle retries and errors gracefully.
If you want, I can show you:
- a Node.js example
- a Python example
- a PHP example
- or how to do it with SendGrid/Mailgun/SES specifically