Yugo.Client (Yugo v1.0.1)

View Source

A persistent connection to an IMAP server.

Normally you do not call the functions in this module directly, but rather start a Client as part of your application's supervision tree. For example:

defmodule MyApp.Application do
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      {Yugo.Client,
       name: :example_client,
       server: "imap.example.com",
       username: "me@example.com",
       password: "pa55w0rd"}
    ]

    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

See start_link for a list of possible arguments.

Summary

Types

The identifier used to refer to a Client.

Functions

Returns a specification to start this module under a supervisor.

Starts an IMAP client process linked to the calling process.

Types

name()

@type name() :: term()

The identifier used to refer to a Client.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(args)

@spec start_link(
  server: String.t(),
  username: String.t(),
  password: String.t(),
  name: name(),
  port: 1..65535,
  tls: boolean(),
  ssl_verify: :verify_none | :verify_peer,
  mailbox: String.t()
) :: GenServer.on_start()

Starts an IMAP client process linked to the calling process.

Takes arguments as a keyword list.

Arguments

  • :username - Required. Username used to log in.

  • :password - Required. Password used to log in.

  • :name - Required. A name used to reference this Client. Can be any term.

  • :server - Required. The location of the IMAP server, e.g. "imap.example.com".

  • :port - The port to connect to the server via. Defaults to 993.

  • :tls - Whether or not to connect using TLS. Defaults to true. If you set this to false, Yugo will make the initial connection without TLS, then upgrade to a TLS connection (using STARTTLS) before logging in. Yugo will never send login credentials over an insecure connection.

  • :mailbox - The name of the mailbox to monitor for emails. Defaults to "INBOX". The default "INBOX" mailbox is defined in the IMAP standard. If your account has other mailboxes, you can pass the name of one as a string. A single Client can only monitor a single mailbox - to monitor multiple mailboxes, you need to start multiple Clients.

Advanced Arguments

The following options are provided because they can be useful, but in most cases you won't need to change them from the default, unless you know what you're doing.

  • :ssl_verify - The :verify option passed to :ssl.connect/2. Can be :verify_peer or :verify_none. Defaults to :verify_peer.

Example

Normally, you do not call this function directly, but rather run it as part of your application's supervision tree. See the top of this page for example Application usage.