internal/protocol
Implementation of https://www.rfc-editor.org/rfc/rfc5321.html
Types
Represents the next action to take in the SMTP protocol state machine.
Send(cmd, next): Send an SMTP command, then continue withnext.Receive(callback): Wait for an SMTP response, then callcallback.Upgrade(next): Upgrade the connection to TLS, then continue withnext.Done: The protocol session has completed successfully.
pub type Action {
Send(String, fn() -> Result(Action, ProtocolError))
Receive(fn(String) -> Result(Action, ProtocolError))
Upgrade(fn() -> Result(Action, ProtocolError))
Done
}
Constructors
-
Send(String, fn() -> Result(Action, ProtocolError)) -
Receive(fn(String) -> Result(Action, ProtocolError)) -
Upgrade(fn() -> Result(Action, ProtocolError)) -
Done
pub type ArgumentError {
EncodingError(encoding.EncoderError)
InvalidAddress(String)
NoFromMailboxSpecified
NoRecipientsSpecified
DataSizeError(actual: Int, allowed: Int)
DataRenderError(internet_message.RenderError)
}
Constructors
-
EncodingError(encoding.EncoderError) -
InvalidAddress(String) -
NoFromMailboxSpecified -
NoRecipientsSpecified -
DataSizeError(actual: Int, allowed: Int) -
DataRenderError(internet_message.RenderError)
Configuration for an SMTP protocol session.
helo_host: The hostname to use in the EHLO/HELO command.credentials: Optional SMTP authentication credentials.
pub type ProtocolConfig {
ProtocolConfig(
helo_host: String,
credentials: option.Option(#(String, String)),
)
}
Constructors
-
ProtocolConfig( helo_host: String, credentials: option.Option(#(String, String)), )
Errors that can occur during SMTP protocol communication.
pub type ProtocolError {
InvalidResponse(response: String)
UnexpectedResponseCode(expected: Int, actual: Int)
InvalidRequestError(ArgumentError)
}
Constructors
-
InvalidResponse(response: String) -
UnexpectedResponseCode(expected: Int, actual: Int) -
InvalidRequestError(ArgumentError)
Callback type for the Receive action. Called with the server response.
pub type ReceiveCallback =
fn(String) -> Result(Action, ProtocolError)
Callback type for the Send action. Called after a command is sent.
pub type SendCallback =
fn() -> Result(Action, ProtocolError)
Values
pub fn start_session(
message message: message.Message,
config config: ProtocolConfig,
) -> Result(Action, ProtocolError)
Start an SMTP protocol session for sending a message.
Executes the full SMTP session: server greeting, EHLO/HELO, STARTTLS, authentication (if configured), and mail transaction (MAIL FROM, RCPT TO, DATA).
message: Thesendr/message.Messageto deliver.config: TheProtocolConfigfor the session.
Returns an Action representing the first action in the protocol sequence.