View Source Mail (mail v0.4.3)
Mail primitive for composing messages.
Build a mail message with the Mail
struct
mail =
Mail.build_multipart()
|> put_subject("How is it going?")
|> Mail.put_text("Just checking in")
|> Mail.put_to("joe@example.com")
|> Mail.put_from("brian@example.com")
Summary
Functions
Returns a unique list of all recipients
Build a single-part mail
Build a multi-part mail
Walks the message parts and collects all attachments
Retrieves the recipients from the bcc
header
Retrieves the recipients from the cc
header
Retrieves the from
header
Find the last html part of a given mail
Retrieves the reply-to
header
Retrieve the subject
header
Find the last text part of a given mail
Retrieves the list of recipients from the to
header
Determines the message has any attachment parts
Determines the message has any text parts
Primary hook for parsing
Add an attachment part to the message
Add new recipients to the bcc
header
Add new recipients to the cc
header
Add a new from
header
Add an HTML part to the message
Add a new reply-to
header
Add a new subject
header
Add a plaintext part to the message
Add new recipients to the to
header
Primary hook for rendering
Functions
Returns a unique list of all recipients
Will collect all recipients from to
, cc
, and bcc
and returns a unique list of recipients.
Build a single-part mail
Build a multi-part mail
Walks the message parts and collects all attachments
Each member in the list is {filename, content}
Retrieves the recipients from the bcc
header
Retrieves the recipients from the cc
header
Retrieves the from
header
Find the last html part of a given mail
RFC 2046, §5.1.4 “In general, the best choice is the LAST part of a type supported by the recipient system's local environment.”
If single part with content-type
"text/html", returns itself
If single part without content-type
"text/html", returns nil
If multipart with part having content-type
"text/html" will return that part
If multipart without part having content-type
"text/html" will return nil
Retrieves the reply-to
header
Retrieve the subject
header
Find the last text part of a given mail
RFC 2046, §5.1.4 “In general, the best choice is the LAST part of a type supported by the recipient system's local environment.”
If single part with content-type
"text/plain", returns itself
If single part without content-type
"text/plain", returns nil
If multipart with part having content-type
"text/plain" will return that part
If multipart without part having content-type
"text/plain" will return nil
Retrieves the list of recipients from the to
header
Determines the message has any attachment parts
Returns a Boolean
Determines the message has any text parts
Returns a Boolean
Primary hook for parsing
You can pass in your own custom parse module. That module
must have a parse/1
function that accepts a string or list of lines
By default the parser
will be Mail.Parsers.RFC2822
Add an attachment part to the message
Mail.put_attachment(%Mail.Message{}, "README.md")
Mail.put_attachment(%Mail.Message{}, {"README.md", data})
Each call will add a new attachment part.
Add new recipients to the bcc
header
Recipients can be added as a single string or a list of strings. The list of recipients will be concated to the previous value.
Examples
iex> Mail.put_bcc(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{"bcc" => ["one@example.com"]}}
iex> Mail.put_bcc(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{"bcc" => ["one@example.com", "two@example.com"]}}
iex> Mail.put_bcc(%Mail.Message{}, "one@example.com")
iex> |> Mail.put_bcc(["two@example.com", "three@example.com"])
%Mail.Message{headers: %{"bcc" => ["one@example.com", "two@example.com", "three@example.com"]}}
The value of a recipient must conform to either a string value or a tuple with two elements,
otherwise an ArgumentError
is raised.
Valid forms:
"user@example.com"
"Test User <user@example.com>"
{"Test User", "user@example.com"}
Add new recipients to the cc
header
Recipients can be added as a single string or a list of strings. The list of recipients will be concated to the previous value.
Examples
iex> Mail.put_cc(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{"cc" => ["one@example.com"]}}
iex> Mail.put_cc(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{"cc" => ["one@example.com", "two@example.com"]}}
iex> Mail.put_cc(%Mail.Message{}, "one@example.com")
iex> |> Mail.put_cc(["two@example.com", "three@example.com"])
%Mail.Message{headers: %{"cc" => ["one@example.com", "two@example.com", "three@example.com"]}}
The value of a recipient must conform to either a string value or a tuple with two elements,
otherwise an ArgumentError
is raised.
Valid forms:
"user@example.com"
"Test User <user@example.com>"
{"Test User", "user@example.com"}
Add a new from
header
Examples
iex> Mail.put_from(%Mail.Message{}, "user@example.com")
%Mail.Message{headers: %{"from" => "user@example.com"}}
Add an HTML part to the message
Mail.put_html(%Mail.Message{}, "<span>Some HTML</span>")
If a text part already exists this function will replace that existing part with the new part.
Options
:charset
- The character encoding standard for content type
Add a new reply-to
header
Examples
iex> Mail.put_reply_to(%Mail.Message{}, "user@example.com")
%Mail.Message{headers: %{"reply-to" => "user@example.com"}}
Add a new subject
header
Examples
iex> Mail.put_subject(%Mail.Message{}, "Welcome to DockYard!")
%Mail.Message{headers: %{"subject" => "Welcome to DockYard!"}}
Add a plaintext part to the message
Shortcut function for adding plain text part
Mail.put_text(%Mail.Message{}, "Some plain text")
If a text part already exists this function will replace that existing part with the new part.
Options
:charset
- The character encoding standard for content type
Add new recipients to the to
header
Recipients can be added as a single string or a list of strings. The list of recipients will be concated to the previous value.
Examples
iex> Mail.put_to(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{"to" => ["one@example.com"]}}
iex> Mail.put_to(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{"to" => ["one@example.com", "two@example.com"]}}
iex> Mail.put_to(%Mail.Message{}, "one@example.com")
iex> |> Mail.put_to(["two@example.com", "three@example.com"])
%Mail.Message{headers: %{"to" => ["one@example.com", "two@example.com", "three@example.com"]}}
The value of a recipient must conform to either a string value or a tuple with two elements,
otherwise an ArgumentError
is raised.
Valid forms:
"user@example.com"
"Test User <user@example.com>"
{"Test User", "user@example.com"}
Primary hook for rendering
You can pass in your own custom render module. That module
must have render/1
function that accepts a Mail.Message
struct.
By default the renderer
will be Mail.Renderers.RFC2822