chronos_smtp

Search:
Group by:

Types

Message = object
ReplyError = object of IOError
Smtp = ref object
  closed*: bool
  case kind*: SmtpClientScheme
  of SmtpClientScheme.NonSecure:
    nil
  of SmtpClientScheme.Secure:
    treader*: AsyncStreamReader
    twriter*: AsyncStreamWriter
    tls*: TLSAsyncStream
    flags*: set[TLSFlags]
  transp*: StreamTransport
  reader*: AsyncStreamReader
  writer*: AsyncStreamWriter
  host*: string
  port*: Port
SmtpClientScheme {.pure.} = enum
  NonSecure, Secure
SmtpError = object of AsyncError

Procs

proc `$`(msg: Message): string {....raises: [], tags: [], forbids: [].}
stringify for Message.
proc auth(smtp: Smtp; username, password: string): Future[void] {.
    ...stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
Sends an AUTH command to the server to login as the username using password. May fail with ReplyError.
proc authCommand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc checkReply(smtp: Smtp; reply: string; quitWhenFailed: bool = true): Future[
    void] {....stackTrace: false, raises: [], gcsafe, tags: [RootEffect],
            forbids: [].}
proc close(smtp: Smtp; quit: bool = true): Future[void] {....stackTrace: false,
    raises: [], gcsafe, tags: [RootEffect], forbids: [].}
Disconnects from the SMTP server and closes the stream.
proc connect(smtp: Smtp; host: string; port: Port; flags: set[TLSFlags] = {};
             helo: bool = true; quitWhenFailed: bool = true): Future[void] {.
    ...stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
Establishes a connection with a SMTP server.
proc createMessage(mSubject, mBody: string; mTo, mCc: seq[string];
                   otherHeaders: openArray[tuple[name, value: string]]): Message {.
    ...raises: [], tags: [], forbids: [].}

Creates a new MIME compliant message.

You need to make sure that mSubject, mTo and mCc don't contain any newline characters. Failing to do so will raise AssertionDefect.

proc createMessage(mSubject, mBody: string; mTo: seq[string] = @[];
                   mCc: seq[string] = @[]): Message {....raises: [], tags: [],
    forbids: [].}

Alternate version of the above.

You need to make sure that mSubject, mTo and mCc don't contain any newline characters. Failing to do so will raise AssertionDefect.

proc dataCommand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc dial(host: string; port: Port; useTls: bool = false;
          flags: set[TLSFlags] = {}; helo: bool = true;
          quitWhenFailed: bool = true): Future[Smtp] {....stackTrace: false,
    raises: [], gcsafe, tags: [RootEffect], forbids: [].}
proc ehlo(smtp: Smtp): Future[bool] {....stackTrace: false, raises: [], gcsafe,
                                      tags: [RootEffect], forbids: [].}
Sends EHLO request.
proc ehloCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc expnCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc helo(smtp: Smtp): Future[void] {....stackTrace: false, raises: [], gcsafe,
                                      tags: [RootEffect], forbids: [].}
proc heloCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc helpCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc lhlo(smtp: Smtp): Future[void] {....stackTrace: false, raises: [], gcsafe,
                                      tags: [RootEffect], forbids: [].}
proc lhloCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc mailCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc newSmtp(useTls: bool = false): Smtp {....raises: [], tags: [], forbids: [].}
proc noopCommand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc quitComand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc rcptCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}
proc read(smtp: Smtp): Future[string] {....stackTrace: false, raises: [], gcsafe,
                                        tags: [RootEffect], forbids: [].}
Return all lines
proc readLine(smtp: Smtp): Future[string] {....stackTrace: false, raises: [],
    gcsafe, tags: [RootEffect], forbids: [].}
proc resetCommand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc send(smtp: Smtp; cmd: string): Future[void] {....stackTrace: false,
    raises: [], gcsafe, tags: [RootEffect], forbids: [].}
proc sendMail(smtp: Smtp; fromAddr: string; toAddrs: seq[string]; msg: string): Future[
    void] {....stackTrace: false, raises: [], gcsafe, tags: [RootEffect],
            forbids: [].}

Sends msg from fromAddr to the addresses specified in toAddrs. Messages may be formed using createMessage by converting the Message into a string.

You need to make sure that fromAddr and toAddrs don't contain any newline characters. Failing to do so will raise AssertionDefect.

proc startTls(smtp: Smtp; flags: set[TLSFlags] = {}): Future[void] {.
    ...stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
Put the SMTP connection in TLS (Transport Layer Security) mode. May fail with ReplyError
proc starttlsCommand(): string {.inline, ...raises: [], tags: [], forbids: [].}
proc vrfyCommand(param: string): string {.inline, ...raises: [], tags: [],
    forbids: [].}