class
Amber::Mailer::SMTPAdapter
- Amber::Mailer::SMTPAdapter
- Amber::Mailer::DeliveryAdapter
- Reference
- Object
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
- Connect to SMTP server
- Read server greeting (220)
- Send EHLO
- Optionally upgrade to TLS via STARTTLS
- Re-send EHLO after TLS upgrade
- Authenticate via AUTH LOGIN if credentials are provided
- Send MAIL FROM, RCPT TO, DATA commands
- Send the MIME message
- Send QUIT
Defined in:
amber/mailer/smtp_adapter.crConstructors
Instance Method Summary
-
#deliver(email : Email) : DeliveryResult
Delivers an email by connecting to the SMTP server and transmitting the message using the SMTP protocol.
- #helo_domain : String
- #helo_domain=(helo_domain : String)
- #host : String
- #host=(host : String)
- #password : String | Nil
- #password=(password : String | Nil)
- #port : Int32
- #port=(port : Int32)
- #use_tls : Bool
- #use_tls=(use_tls : Bool)
- #username : String | Nil
- #username=(username : String | Nil)
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")
#
Instance Method Detail
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.