Cursor email

SMTP Connection Refused in Production for Cursor-Generated Email Code

Your Cursor-generated application sends emails perfectly during local development but fails with SMTP connection errors in production. Users aren't receiving signup confirmations, password resets, or notification emails. The server logs show connection refused, timeout, or authentication errors when attempting to connect to the mail server.

Email delivery is critical infrastructure — when it breaks, users can't sign up, can't reset passwords, and lose trust in your application. Cursor often generates SMTP code configured for a local mail server or development service like Mailtrap/Mailhog, which doesn't translate to production.

The issue might also manifest as emails being sent successfully according to your application logs, but never arriving in users' inboxes due to DNS, SPF, or deliverability configuration problems that only affect production domains.

Error Messages You Might See

Error: connect ECONNREFUSED 127.0.0.1:25 Error: connect ETIMEDOUT smtp.gmail.com:587 Error: Invalid login: 535 5.7.8 Authentication failed Error: self signed certificate in certificate chain getaddrinfo ENOTFOUND smtp.mailtrap.io
Error: connect ECONNREFUSED 127.0.0.1:25Error: connect ETIMEDOUT smtp.gmail.com:587Error: Invalid login: 535 5.7.8 Authentication failedError: self signed certificate in certificate chaingetaddrinfo ENOTFOUND smtp.mailtrap.io

Common Causes

  • Port 25 blocked by cloud provider — AWS, GCP, Azure, and most cloud providers block outbound SMTP port 25 by default to prevent spam. You need to use port 587 (STARTTLS) or 465 (SSL/TLS)
  • Development SMTP credentials in production — Cursor configured Mailtrap, Mailhog, or localhost:1025 credentials that only work in development
  • Missing or wrong TLS/SSL configuration — Production SMTP servers require TLS encryption but the code uses plain text connections, or uses SSL when STARTTLS is expected
  • Firewall or security group blocking outbound — The production server's security group or network ACL doesn't allow outbound connections on port 587 or 465
  • SMTP authentication method mismatch — The email provider requires OAuth2 authentication (like Gmail) but the code uses plain username/password
  • DNS resolution failing for SMTP host — The SMTP hostname can't be resolved from the production environment due to internal DNS or networking constraints

How to Fix It

  1. Use port 587 with STARTTLS — Configure your SMTP connection to use port 587 with STARTTLS encryption. This is the standard for authenticated email submission and is not blocked by cloud providers
  2. Switch to an email API service — Replace SMTP with an HTTP-based email API like SendGrid, Resend, Postmark, or AWS SES. These are more reliable than SMTP in serverless/cloud environments and include deliverability features
  3. Verify production environment variables — Check that SMTP_HOST, SMTP_PORT, SMTP_USER, and SMTP_PASS are set correctly in your production environment, not pointing to development values
  4. Check cloud provider email restrictions — If on AWS, you may need to request removal of the port 25 throttle. On most providers, using SES or a third-party email API is the recommended approach
  5. Test SMTP connectivity from production — SSH into your production server and run openssl s_client -connect smtp.provider.com:587 -starttls smtp to verify the connection is possible
  6. Configure SPF, DKIM, and DMARC — Even if SMTP connects, emails may be rejected without proper DNS records for your sending domain

Real developers can help you.

Vlad Temian Vlad Temian 15+ years shipping production infrastructure for startups. Former CTO at qed.builders (acquired by The Sandbox). Cursor ambassador and agentic tooling builder. I've scaled systems, automated deployments, and built observability tools for AI coding workflows. I specialize in taking vibe-coded apps from broken prototype to production-ready: fixing Supabase auth/RLS, Stripe integrations, deployment pipelines, and cleaning up AI-generated spaghetti. I build tools in this space (agentprobe, claudebin, micode) and understand both sides: how AI generates code and why it breaks. https://blog.vtemian.com/ BurnHavoc BurnHavoc Been around fixing other peoples code for 20 years. Nam Tran Nam Tran 10 years as fullstack developer Yovel Cohen Yovel Cohen I got a lot of experience in building Long-horizon AI Agents in production, Backend apps that scale to millions of users and frontend knowledge as well. Meïr Ankri Meïr Ankri Full-stack developer specializing in React / Next.js / Node.js with 6+ years of experience. I've worked across various sectors including automotive (Reezocar/Société Générale), healthcare (Medical Link SaaS), and e-commerce (Glasman). I build web apps end-to-end, from architecture to production, with a focus on scalability, performance, and code quality. I also mentor junior developers and contribute to technical decisions and code reviews. rayush33 rayush33 JavaScript (React.js, React Native, Node.js) Developer with demonstrated industry experience of 4+ years, actively looking for opportunities to hone my skills as well as help small-scale business owners with solutions to technical problems Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. Matt Butler Matt Butler Software Engineer @ AWS Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : )

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Why does email work locally but not in production?

Local development often uses a local SMTP server (Mailhog, Mailtrap) or your machine has no firewall restrictions. Production environments block port 25, require TLS, and need real SMTP credentials. Switch to an email API service like SendGrid or Resend for reliable production email.

Should I use SMTP or an email API?

For production apps, use an HTTP-based email API (SendGrid, Resend, Postmark, AWS SES). They're more reliable than SMTP in cloud/serverless environments, handle retries automatically, and include deliverability monitoring and analytics.

Related Cursor Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help