Prompt
send email API
Latest observation
Sep 24, 2026
OpenAI APIWeb search: off
Sure — if you want to send an email via an API, here’s a simple example using Node.js + Nodemailer for SMTP, or SendGrid/Mailgun if you want a hosted email API.
Example: Send email with a REST API using Node.js
1) Install
npm install express nodemailer
2) Create API endpoint
const express = require('express');
const nodemailer = require('nodemailer');
const app = express();
app.use(express.json());
app.post('/send-email', async (req, res) => {
const { to, subject, text } = req.body;
try {
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
const info = await transporter.sendMail({
from: process.env.EMAIL_USER,
to,
subject,
text,
});
res.json({ success: true, messageId: info.messageId });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
app.listen(3000, () => console.log('API running on port 3000'));
3) Call the API
curl -X POST http://localhost:3000/send-email \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Hello",
"text": "This is a test email"
}'
If you meant “send email API” in another stack:
- Python: Flask + smtplib / SendGrid SDK
- PHP: Laravel Mail / PHPMailer
- Java: Spring Boot + JavaMailSender
- C#: ASP.NET + MailKit
- JavaScript frontend: call your backend API only; don’t send SMTP creds from browser
If you want, I can give you:
- a complete email-sending API in your preferred language, or
- an integration with SendGrid, Mailgun, AWS SES, or Gmail.