# Module smtp

This module implements the SMTP client protocol as specified by RFC 5321, this can be used to send mail to any SMTP Server.

This module also implements the protocol used to format messages, as specified by RFC 2822.

Example gmail use:

    var msg = createMessage("Hello from Nimrod's SMTP",
                            "Hello!.\n Is this awesome or what?",
                            @["foo@gmail.com"])
    var smtp = connect("smtp.gmail.com", 465, True, True)
    smtp.auth("username", "password")
    smtp.sendmail("username@gmail.com", @["foo@gmail.com"], $msg)

For SSL support this module relies on OpenSSL. If you want to enable SSL, compile with `-d:ssl`.

# Imports

sockets, strutils, strtabs, base64, os

# Types

    TSMTP* {.final.} = object
      sock: TSocket
      debug: Bool

    TMessage* {.final.} = object
      msgTo: seq[string]
      msgCc: seq[string]
      msgSubject: string
      msgOtherHeaders: PStringTable
      msgBody: string

    EInvalidReply* = object of EIO

# Procs

    proc connect*(address: string; port = 25; ssl = false; debug = false): TSMTP

  Establishes a connection with a SMTP server. May fail with EInvalidReply or with a socket error.

    proc auth*(smtp: var TSMTP; username, password: string)

  Sends an AUTH command to the server to login as the username using password. May fail with EInvalidReply.

    proc sendmail*(smtp: var TSMTP; fromaddr: string; toaddrs: seq[string];
                   msg: string)

  Sends msg from fromaddr to toaddr. Messages may be formed using `createMessage` by converting the TMessage into a string.

    proc close*(smtp: TSMTP)

  Disconnects from the SMTP server and closes the socket.

    proc createMessage*(mSubject, mBody: string; mTo, mCc: seq[string];
                        otherHeaders: openarray[tuple[name, value: string]]): TMessage

  Creates a new MIME compliant message.

    proc createMessage*(mSubject, mBody: string; mTo, mCc: seq[string] = @ []): TMessage

  Alternate version of the above.

    proc `$`*(msg: TMessage): string

  stringify for `TMessage`.

Generated: 2012-09-23 21:47:54 UTC