Currently Available: Need a skilled Software Developer for your next project?
Categories
Email Laravel

Sending and Receiving Emails in Laravel Applications

Implementing email functionality is far from straightforward. The right solution depends on your specific needs, user base, and resources.

Sending and Receiving

Sending and receiving emails are two separate concerns.

Sending Emails

The Basics: SMTP

At its core, sending emails typically relies on the SMTP (Simple Mail Transfer Protocol).

Your email hosting company provides you with SMTP credentials:

  • SMTP server address
  • Username
  • Password

These are the same credentials you'd use in email clients like Outlook or Thunderbird. In Laravel, you can use these credentials to send emails.

Gmail and Outlook

Here's where things get tricky. Most people today use Gmail (or Google Workspace) or Outlook/Office 365. These providers have made developers' lives significantly harder.

Gmail Challenges:
  1. No more simple SMTP credentials
  2. Multiple access methods, each with drawbacks:
    • Registering as a public app:
      • Requires a thorough security audit
      • Time-consuming and expensive
      • Must pass several major security topics
    • Application passwords:
      • Only available for users with two-factor authentication
      • Complicated process, especially for non-technical users
Outlook/Office 365 Challenges:
  1. Need to register your app in Microsoft's Azure Directory
  2. Implement OAuth2 workflow for user authorization
  3. Users may need to enable SMTP in their accounts manually

The integration process for both these providers is labor-intensive and complex.

Specialized Email Providers

Services like Mailgun, Postmark, and SendGrid offer simpler solutions:

Pros:

  • Easy setup with API and/or SMTP access
  • Reliable delivery

Cons:

  1. Domain configuration required for each sender domain
  2. Primarily for transactional emails
  3. Marketing emails may face deliverability issues
  4. Strict opt-in requirements for recipients of marketing emails

Volume Considerations

The number of emails you send matters:

  • Low volume: Most hosting providers won't cause issues
  • High volume: Becomes challenging, especially for non-transactional emails

Receiving Emails

IMAP Basics

Receiving emails typically uses the IMAP (Internet Message Access Protocol). Your email host provides IMAP server credentials, similar to SMTP.

Challenges with IMAP:

  1. Pull mechanism: Requires constant checking for new emails
  2. Often slow and clunky
  3. Resource-intensive for multiple user accounts

Gmail and Outlook Issues (Again)

The same OAuth2 and app password issues apply here as with sending emails.

Processing Email Content

Once you've received an email, you need to:

  1. Parse the email content (which can be complex)
  2. Filter out spam and auto-replies

Inbound Email Routing Services

Services like Mailgun and Postmark offer inbound routing:

  • Receive webhook with email content
  • Often provide parsed content
  • May include spam/autoreply detection

User setup typically involves email forwarding to a provided address.

The EmailEngine Solution

EmailEngine is a self-hosted tool that aims to simplify email integration:

  • Unified REST API for IMAP, SMTP, Gmail API, and Microsoft Graph API
  • Self-hosted solution
  • Priced at €895.00 / year

Pros:

  • Handles OAuth2 workflows
  • Provides a consistent API across providers

Cons:

  • Requires self-hosting
  • Still needs significant integration work
  • Doesn't eliminate all the challenges mentioned above
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *