What an email server does and why you need to pick one
An email server is the machine that actually sends or receives your messages. When you write code that needs to send an email — a password reset, an order confirmation, a notification — that code connects to an email server and hands off the message. The server then handles delivery to the recipient's inbox.
You have two main choices: run your own server on hardware you control, or use a third-party service that runs servers for you. Most developers choose the third-party route because running a mail server yourself requires constant maintenance, security updates, and technical knowledge to keep messages from landing in spam folders.
The email server you pick affects how your code connects (the protocol), what credentials you need, whether your messages reach inboxes or spam, and how much you pay. Getting this decision right early saves you from rewriting connection code later.
Key Takeaways
- Third-party email services (SendGrid, Mailgun, AWS SES, Postmark) are simpler than running your own server and include spam-filtering reputation that helps messages reach inboxes.
- SMTP is the protocol your code uses to send mail; IMAP is for reading mail — most applications only need SMTP unless they're building an email client.
- Each service provides an SMTP hostname, port number, and credentials (username and password or API key) that you store in your process's configuration, never in your code.
- Transactional email services (for automated messages like password resets) and bulk email services (for newsletters) have different pricing and features — pick the type that matches what you're sending.
- Test your connection in a development environment before deploying to production, because connection errors often don't surface until you actually try to send.
Third-party email services versus running your own server
Running your own email server means installing software like Postfix or Exim on a machine you own or rent, configuring DNS records so other servers trust yours, and monitoring deliverability constantly. You also become responsible for security patches, spam filtering, and the reputation of your server's IP address — if someone abuses it, your messages get blocked everywhere.
A third-party service handles all of that. SendGrid, Mailgun, AWS SES, Postmark, and similar providers maintain the infrastructure, manage IP reputation, and provide tools to track bounces and complaints. You pay per message or per month, connect via SMTP or an API, and let them worry about whether your mail reaches Gmail or Outlook.
For most applications — especially if you're sending transactional mail like password resets or order confirmations — a third-party service is the practical choice. The cost is low (often free up to a few hundred messages per day), and your messages are far more likely to reach inboxes because the service's reputation is already established.
SMTP, IMAP, and which protocol your code actually needs
SMTP (straightforward Mail Transfer Protocol) is how your code sends mail. When you configure an email server in your process, you're almost always configuring SMTP. Your code connects to the server's SMTP port (usually 587 or 465), authenticates with a username and password or API key, and hands over the message.
IMAP (Internet Message Access Protocol) is how mail clients like Outlook or Apple Mail read messages from a server. Unless you're building an email client or a system that needs to read incoming mail from a mailbox, you don't need IMAP. Most web applications only send mail, so they only need SMTP.
A few applications do need to read mail — for example, a support ticket system that creates tickets from incoming emails, or a calendar app that processes meeting invitations. In those cases, you'd configure both SMTP (to send) and IMAP (to read). But start by assuming you only need SMTP, because that's what 95% of applications use.
What information you need from your email service
When you sign up for a third-party email service, you'll receive a set of connection details. Write these down or store them in a password manager — you'll need them to configure your process:
- SMTP hostname: The address of the server (for example, smtp.sendgrid.net or smtp.mailgun.org). This goes in your process's email configuration.
- SMTP port: Usually 587 (for TLS encryption) or 465 (for SSL encryption). Some services support both; use 587 unless you have a reason not to.
- Username: Often "apikey" for services that use API keys, or an actual email address for traditional SMTP.
- Password or API key: A long string that authenticates you to the server. Treat this like a password — never commit it to version control or put it in your code.
- From address: The email address that will appear in the "From" field of messages you send. Some services require you to verify this address first.
Store these credentials in environment variables or a configuration file that's not tracked in Git. Your code reads from the environment at runtime, so the actual credentials never appear in your repository.
Transactional versus bulk email services
Transactional email services are built for automated, one-to-one messages: password resets, order confirmations, shipping notifications, two-factor authentication codes. These messages are usually triggered by a user action and sent when ready. Services like Postmark, SendGrid, and Mailgun all handle transactional mail well.
Bulk email services are built for newsletters and marketing campaigns sent to many recipients at once. They include list management, unsubscribe handling, and compliance with anti-spam laws. Services like Klaviyo, Constant Contact, and ConvertKit focus on bulk mail.
The distinction matters because transactional services charge per message (often very cheaply — fractions of a cent), while bulk services charge per subscriber or per campaign. If you're sending a password reset to one user, transactional pricing is far cheaper. If you're sending a weekly newsletter to 10,000 subscribers, bulk pricing makes more sense. Some services, like SendGrid, offer both, so you can use one service for both types of mail.
Testing your connection before going live
Before you deploy your process to production, test the email connection in a development environment. Write a small script that connects to the SMTP server using your credentials and sends a test message to yourself. This catches configuration errors — wrong hostname, wrong port, wrong credentials, firewall blocking — before your users encounter them.
Most programming languages have libraries that make this straightforward. In Python, you'd use smtplib; in Node.js, you'd use nodemailer; in PHP, you'd use PHPMailer or Swift Mailer. Each library handles the SMTP protocol for you — you just provide the hostname, port, credentials, and message content.
Common mistakes at this stage: using port 25 (which is blocked by most hosting providers), forgetting to enable TLS encryption, storing credentials in your code instead of environment variables, and not verifying the "From" address with the email service. Test in development first, and these problems surface when ready instead of after deployment.
Deliverability and why your messages might land in spam
Even with a reputable email service, your messages can land in spam if you don't follow basic practices. The biggest factors are your sender reputation (which the email service manages for you), whether you've set up SPF and DKIM records (DNS records that prove you're authorized to send from your domain), and whether recipients are actually expecting your mail.
Most third-party services provide instructions for setting up SPF and DKIM. These are one-time DNS configuration tasks that tell Gmail, Outlook, and other providers that your email service is authorized to send mail on your behalf. If you skip this step, your messages are much more likely to be flagged as spam.
The other factor is list hygiene: if you're sending to addresses that don't exist or that have marked your mail as spam before, your sender reputation drops. Most email services track bounces and complaints and let you see which addresses are problematic. Remove them from your list, and your deliverability improves.
Frequently Asked Questions
Can I use Gmail's SMTP server to send mail from my process?
Technically yes, but it's not recommended. Gmail's SMTP server (smtp.gmail.com) has strict rate limits and is designed for personal email clients, not applications. If your app sends more than a few messages per day, Gmail will block you. Use a service built for applications instead.
What's the difference between port 587 and port 465?
Both encrypt your connection, but they do it differently. Port 587 uses STARTTLS (encryption starts after you connect), while port 465 uses implicit TLS (encryption from the moment you connect). Most services support both. Use 587 unless the service tells you otherwise.
Do I need to verify my domain before sending mail?
Most services require you to verify that you own the domain you're sending from. This usually means adding a DNS record that the service provides. It's a one-time setup that takes a few minutes and prevents someone else from impersonating your domain.
What happens if my email service goes down?
If the service is temporarily unavailable, your process should retry sending the message after a delay. Most email libraries handle this automatically. For critical messages like password resets, consider queuing the message in a database and retrying every few minutes until it succeeds.
Can I send mail from multiple domains using one service?
Yes. Most services let you add multiple domains and verify each one. You then specify which domain to send from in each message. This is useful if your process serves multiple brands or if you want to separate transactional mail from marketing mail.