Prompt
How to send email from Express
Latest observation
Aug 13, 2026 · OpenAI APIWeb search: off
To send email from an Express app, the usual approach is to use Nodemailer.
1) Install Nodemailer
npm install nodemailer
2) Create a mail transporter
Example with Gmail SMTP:
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS, // use an App Password for Gmail
},
});
3) Send an email in an Express route
const express = require("express");
const nodemailer = require("nodemailer");
require("dotenv").config();
const app = express();
app.use(express.json());
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
app.post("/send-email", async (req, res) => {
try {
const { to, subject, text } = req.body;
const info = await transporter.sendMail({
from: process.env.EMAIL_USER,
to,
subject,
text,
});
res.json({ message: "Email sent", id: info.messageId });
} catch (error) {
console.error(error);
res.status(500).json({ message: "Failed to send email" });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));
4) Add environment variables
Create a .env file:
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
5) Test the endpoint
Send a POST request to /send-email:
{
"to": "someone@example.com",
"subject": "Hello",
"text": "This is a test email"
}
Notes
- For Gmail, you usually need an App Password if 2FA is enabled.
- For production, use a proper email service like:
- SendGrid
- Mailgun
- Amazon SES
- Postmark
If you want, I can also show:
- sending HTML emails, or
- a complete Express + Nodemailer example with attachments.
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.