class Amber::Mailer::SMTPAdapter

Overview

SMTP delivery adapter for sending emails via an SMTP server.

Implements the SMTP protocol using Crystal's standard library Socket and OpenSSL modules. Supports STARTTLS for encrypted connections and AUTH LOGIN for authentication.

Usage

adapter = SMTPAdapter.new(
  host: "smtp.example.com",
  port: 587,
  username: "[email protected]",
  password: "secret",
  use_tls: true,
  helo_domain: "myapp.com"
)

result = adapter.deliver(email)

SMTP Protocol Flow

  1. Connect to SMTP server
  2. Read server greeting (220)
  3. Send EHLO
  4. Optionally upgrade to TLS via STARTTLS
  5. Re-send EHLO after TLS upgrade
  6. Authenticate via AUTH LOGIN if credentials are provided
  7. Send MAIL FROM, RCPT TO, DATA commands
  8. Send the MIME message
  9. Send QUIT

Defined in:

amber/mailer/smtp_adapter.cr

Constructors

Instance Method Summary

Instance methods inherited from class Amber::Mailer::DeliveryAdapter

deliver(email : Email) : DeliveryResult deliver

Constructor Detail

def self.new(host : String = "localhost", port : Int32 = 25, username : String | Nil = nil, password : String | Nil = nil, use_tls : Bool = false, helo_domain : String = "localhost") #

[View source]

Instance Method Detail

def deliver(email : Email) : DeliveryResult #

Delivers an email by connecting to the SMTP server and transmitting the message using the SMTP protocol.

Returns a DeliveryResult indicating whether the delivery succeeded. On failure, the error message contains details about what went wrong.


[View source]
def helo_domain : String #

[View source]
def helo_domain=(helo_domain : String) #

[View source]
def host : String #

[View source]
def host=(host : String) #

[View source]
def password : String | Nil #

[View source]
def password=(password : String | Nil) #

[View source]
def port : Int32 #

[View source]
def port=(port : Int32) #

[View source]
def use_tls : Bool #

[View source]
def use_tls=(use_tls : Bool) #

[View source]
def username : String | Nil #

[View source]
def username=(username : String | Nil) #

[View source]