Prompt

how to send emails from backend code

Technology / API Platforms1 observationLast seen Nov 8, 2026

Latest observation

Nov 8, 2026OpenAI APIWeb search: off

To send emails from backend code, you generally use an SMTP server or a third-party email API.

Common approaches

1) Use an email service provider

Examples: SendGrid, Mailgun, Amazon SES, Postmark, Resend

This is usually the easiest and most reliable option for production.

Typical steps:

  1. Create an account with the provider.
  2. Verify your domain.
  3. Get API keys or SMTP credentials.
  4. Install their SDK or use SMTP from your backend.
  5. Send email from your server code.

2) Use SMTP directly

You can connect to an SMTP server from your backend using libraries in your language.

Example concept:

  • host: smtp.gmail.com or provider SMTP host
  • port: 587 or 465
  • username/password or app password
  • send mail via a mail library

Example: Node.js with Nodemailer

const nodemailer = require('nodemailer');

async function sendEmail() {
  let transporter = nodemailer.createTransport({
    host: 'smtp.example.com',
    port: 587,
    secure: false,
    auth: {
      user: 'your-email@example.com',
      pass: 'your-password'
    }
  });

  let info = await transporter.sendMail({
    from: '"My App" <your-email@example.com>',
    to: 'user@example.com',
    subject: 'Hello',
    text: 'This is a test email',
    html: '<b>This is a test email</b>'
  });

  console.log('Message sent:', info.messageId);
}

sendEmail().catch(console.error);

Example: Python with smtplib

import smtplib
from email.mime.text import MIMEText

msg = MIMEText("This is a test email")
msg["Subject"] = "Hello"
msg["From"] = "your-email@example.com"
msg["To"] = "user@example.com"

with smtplib.SMTP("smtp.example.com", 587) as server:
    server.starttls()
    server.login("your-email@example.com", "your-password")
    server.send_message(msg)

print("Email sent")

Important best practices

  • Never hardcode credentials in source code.
  • Store secrets in environment variables.
  • Use app passwords if using Gmail/Outlook.
  • Configure SPF, DKIM, and DMARC for better deliverability.
  • Consider using a queue/background job if sending many emails.
  • Always validate user input to prevent abuse.

Which method should you choose?

  • Small project / testing: SMTP or a simple API provider
  • Production app: Email API provider like SendGrid, SES, Postmark, or Resend

If you want, I can show you how to send emails in your backend language (Node.js, Python, Java, PHP, Go, C#, etc.).

Observation history

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, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.