sendr_smtp
Types
Errors related to the network connection to the SMTP server.
Closed: The connection was closed by the server.Timeout: The operation timed out.PosixError: A POSIX system error occurred.SslNotStarted: The SSL/TLS application was not started.TlsAlert: A TLS alert was received from the server.
pub type ConnectionError {
Closed
Timeout
PosixError(PosixError)
SslNotStarted
TlsAlert(TlsAlert, String)
}
Constructors
-
ClosedThe connection was closed.
-
TimeoutThe operation timed out.
-
PosixError(PosixError)A POSIX error.
-
SslNotStartedThe SSL application has not been started. It probably failed to start.
-
TlsAlert(TlsAlert, String)A TLS alert.
SMTP authentication credentials (username and password).
pub type Credentials {
Credentials(username: String, password: String)
}
Constructors
-
Credentials(username: String, password: String)
POSIX error codes.
See the Erlang inet documentation for descriptions of each error code.
pub type PosixError {
Eaddrinuse
Eaddrnotavail
Eafnosupport
Ealready
Econnaborted
Econnrefused
Econnreset
Edestaddrreq
Ehostdown
Ehostunreach
Einprogress
Eisconn
Emsgsize
Enetdown
Enetreset
Enetunreach
Enopkg
Enoprotoopt
Enotconn
Enotty
Enotsock
Eproto
Eprotonosupport
Eprototype
Esocktnosupport
Etimedout
Ewouldblock
Exbadport
Exbadseq
Nxdomain
Eacces
Eagain
Ebadf
Ebadmsg
Ebusy
Edeadlk
Edeadlock
Edquot
Eexist
Efault
Efbig
Eftype
Eintr
Einval
Eio
Eisdir
Eloop
Emfile
Emlink
Emultihop
Enametoolong
Enfile
Enobufs
Enodev
Enolck
Enolink
Enoent
Enomem
Enospc
Enosr
Enostr
Enosys
Enotblk
Enotdir
Enotsup
Enxio
Eopnotsupp
Eoverflow
Eperm
Epipe
Erange
Erofs
Eshutdown
Espipe
Esrch
Estale
Etxtbsy
Exdev
}
Constructors
-
Eaddrinuse -
Eaddrnotavail -
Eafnosupport -
Ealready -
Econnaborted -
Econnrefused -
Econnreset -
Edestaddrreq -
Ehostdown -
Ehostunreach -
Einprogress -
Eisconn -
Emsgsize -
Enetdown -
Enetreset -
Enetunreach -
Enopkg -
Enoprotoopt -
Enotconn -
Enotty -
Enotsock -
Eproto -
Eprotonosupport -
Eprototype -
Esocktnosupport -
Etimedout -
Ewouldblock -
Exbadport -
Exbadseq -
Nxdomain -
Eacces -
Eagain -
Ebadf -
Ebadmsg -
Ebusy -
Edeadlk -
Edeadlock -
Edquot -
Eexist -
Efault -
Efbig -
Eftype -
Eintr -
Einval -
Eio -
Eisdir -
Eloop -
Emfile -
Emlink -
Emultihop -
Enametoolong -
Enfile -
Enobufs -
Enodev -
Enolck -
Enolink -
Enoent -
Enomem -
Enospc -
Enosr -
Enostr -
Enosys -
Enotblk -
Enotdir -
Enotsup -
Enxio -
Eopnotsupp -
Eoverflow -
Eperm -
Epipe -
Erange -
Erofs -
Eshutdown -
Espipe -
Esrch -
Estale -
Etxtbsy -
Exdev
Configuration for connecting to an SMTP server.
hostname: The SMTP server hostname.port: The SMTP server port.tls: The TLS configuration.timeout_ms: Timeout in milliseconds for network operations.helo_host: Custom hostname for the EHLO/HELO command, if none given the hostname is guessed. If guessing fails localhost is used.credentials: Optional authentication credentials.
pub type SmtpConfig {
SmtpConfig(
hostname: String,
port: Int,
tls: Tls,
timeout_ms: Int,
helo_host: option.Option(String),
credentials: option.Option(Credentials),
)
}
Constructors
-
SmtpConfig( hostname: String, port: Int, tls: Tls, timeout_ms: Int, helo_host: option.Option(String), credentials: option.Option(Credentials), )
Errors that can occur when sending an email via SMTP.
pub type SmtpError {
ConnectionError(ConnectionError)
ProtocolError(protocol.ProtocolError)
}
Constructors
-
ConnectionError(ConnectionError) -
ProtocolError(protocol.ProtocolError)
TLS alert descriptions as defined in the Erlang ssl module documentation.
pub type TlsAlert {
CloseNotify
UnexpectedMessage
BadRecordMac
RecordOverflow
HandshakeFailure
BadCertificate
UnsupportedCertificate
CertificateRevoked
CertificateExpired
CertificateUnknown
IllegalParameter
UnknownCa
AccessDenied
DecodeError
DecryptError
ExportRestriction
ProtocolVersion
InsufficientSecurity
InternalError
InappropriateFallback
UserCanceled
NoRenegotiation
UnsupportedExtension
CertificateUnobtainable
UnrecognizedName
BadCertificateStatusResponse
BadCertificateHashValue
UnknownPskIdentity
NoApplicationProtocol
}
Constructors
-
CloseNotify -
UnexpectedMessage -
BadRecordMac -
RecordOverflow -
HandshakeFailure -
BadCertificate -
UnsupportedCertificate -
CertificateRevoked -
CertificateExpired -
CertificateUnknown -
IllegalParameter -
UnknownCa -
AccessDenied -
DecodeError -
DecryptError -
ExportRestriction -
ProtocolVersion -
InsufficientSecurity -
InternalError -
InappropriateFallback -
UserCanceled -
NoRenegotiation -
UnsupportedExtension -
CertificateUnobtainable -
UnrecognizedName -
BadCertificateStatusResponse -
BadCertificateHashValue -
UnknownPskIdentity -
NoApplicationProtocol
Values
pub fn allow_invalid_certs(
config config: SmtpConfig,
set allow_invalid_certs: Bool,
) -> SmtpConfig
Set whether to allow invalid TLS certificates.
pub fn config(
connect_to hostname: String,
on port: Int,
) -> SmtpConfig
Create a default SmtpConfig for the given hostname and port.
Automatically sets TLS mode based on the port:
-
Port 465:
ImplicitTlswithallow_invalid_certs: False -
Other ports:
StartTlswithallow_invalid_certs: TrueDefault timeout is 10 seconds. -
hostname: The SMTP server hostname. -
port: The SMTP server port.
Returns a new SmtpConfig.
pub fn credentials(
config config: SmtpConfig,
username username: String,
password password: String,
) -> SmtpConfig
Set the SMTP authentication credentials on the config.
pub fn deliver(
email message: message.Message,
with config: SmtpConfig,
) -> Result(Nil, sendr.SendrError(SmtpError))
Deliver an email message via SMTP.
Validates the message fields upfront, then connects to the SMTP server, performs the SMTP protocol session, and disconnects.
message: Thesendr/message.Messageto deliver.config: TheSmtpConfigfor the connection.
Returns Ok(Nil) on success, or Error(SendrError(SmtpError)) if
validation or delivery fails.
pub fn helo_host(
config config: SmtpConfig,
set helo_host: String,
) -> SmtpConfig
Set a custom hostname for the EHLO/HELO command.
pub fn port(
config config: SmtpConfig,
set port: Int,
) -> SmtpConfig
Set the SMTP server port on the config.
pub fn tls_mode(
config config: SmtpConfig,
set tls_mode: TlsMode,
) -> SmtpConfig
Set the TLS mode on the config.