Types
MXHost = object preference*: int ## The preference value of the MX host, where lower values indicate higher priority. host*: string ## The hostname of the MX server to which mail should be delivered.
- Represents an MX host with its preference value and hostname.
MXProviderConfig = object heloName*: string = "localhost" ## The HELO/EHLO name to use when connecting to MX hosts. ## This can be configured to improve compatibility with ## certain mail servers that expect a valid domain name connectTimeoutMs*: int = 7000 ## The timeout in milliseconds for establishing a connection ## to an MX host. If the connection commandTimeoutMs*: int = 10000 ## The timeout in milliseconds for waiting for responses ## to SMTP commands during the delivery process. requireStartTls*: bool ## Whether to require STARTTLS support from MX hosts. If set to true, ## the provider will only attempt delivery to MX hosts that advertise ## STARTTLS in their EHLO response. This can improve security ## but may reduce deliverability if some recipient domains do ## not support STARTTLS. maxMxHostsPerDomain*: int = 5 ## The maximum number of MX hosts to consider for each ## recipient domain. This limits the number of connection attempts ## and can help avoid long delays when a domain has many MX records. debug*: bool = false ## Whether to enable debug logging for the MX provider. ## When enabled, the provider will log detailed
Procs
proc initMXProviderConfig(heloName: string; connectTimeoutMs: int = 7000; commandTimeoutMs: int = 10000; requireStartTls: bool = false; maxMxHostsPerDomain: int = 5; debug: bool = false): MXProviderConfig {. ...raises: [], tags: [], forbids: [].}
- Initializes an MXProviderConfig object with the specified parameters This function provides a convenient way to create a configuration object for the MX provider with custom settings.
proc newMXProvider(cfg = MXProviderConfig()): DeliveryProvider {....raises: [], tags: [], forbids: [].}
-
Creates a new MX delivery provider with the specified configuration. The returned provider will attempt to deliver messages directly to recipient domains by resolving their MX records and performing SMTP transactions.
This provider is suitable for production use but can also be used for testing with local domains and custom MX records
proc resolveMxHosts(domain: string; maxHosts = 5): seq[MXHost] {. ...raises: [OSError, IOError], tags: [ExecIOEffect, ReadIOEffect, RootEffect], forbids: [].}
- Temporary resolver via dig (available on macOS by default). Later replace with c-ares / native DNS.