mail v0.2.2 Mail
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")
Link to this section 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 html part of a given mail
Retrieves the reply-to
header
Retrieve the subject
header
Find the 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
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
Link to this section Functions
all_recipients(message)
Returns a unique list of all recipients
Will collect all recipients from to
, cc
, and bcc
and returns a unique list of recipients.
build()
Build a single-part mail
build_multipart()
Build a multi-part mail
get_attachments(message)
Walks the message parts and collects all attachments
Each member in the list is {filename, content}
get_bcc(message)
Retrieves the recipients from the bcc
header
get_cc(message)
Retrieves the recipients from the cc
header
get_from(message)
Retrieves the from
header
get_html(message)
Find the html part of a given mail
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
get_reply_to(message)
Retrieves the reply-to
header
get_subject(message)
Retrieve the subject
header
get_text(message)
Find the text part of a given mail
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
get_to(message)
Retrieves the list of recipients from the to
header
has_attachments?(message)
Determines the message has any attachment parts
Returns a Boolean
has_text_parts?(message)
Determines the message has any text parts
Returns a Boolean
put_attachment(message, path_or_file_tuple, opts \\ [])
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.
put_bcc(message, recipients)
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.
Mail.put_bcc(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{bcc: ["one@example.com"]}}
Mail.put_bcc(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{bcc: ["one@example.com", "two@example.com"]}}
Mail.put_bcc(%Mail.Message{}, "one@example.com")
|> 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"}
put_cc(message, recipients)
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.
Mail.put_cc(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{cc: ["one@example.com"]}}
Mail.put_cc(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{cc: ["one@example.com", "two@example.com"]}}
Mail.put_cc(%Mail.Message{}, "one@example.com")
|> 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"}
put_from(message, sender)
Add a new from
header
Mail.put_from(%Mail.Message{}, "user@example.com")
%Mail.Message{headers: %{from: "user@example.com"}}
put_html(message, body, opts \\ [])
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
put_reply_to(message, reply_address)
Add a new reply-to
header
Mail.put_reply_to(%Mail.Message{}, "user@example.com")
%Mail.Message{headers: %{reply_to: "user@example.com"}}
put_subject(message, subject)
Add a new subject
header
Mail.put_subject(%Mail.Message{}, "Welcome to DockYard!")
%Mail.Message{headers: %{subject: "Welcome to DockYard!"}}
put_text(message, body, opts \\ [])
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
put_to(message, recipients)
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.
Mail.put_to(%Mail.Message{}, "one@example.com")
%Mail.Message{headers: %{to: ["one@example.com"]}}
Mail.put_to(%Mail.Message{}, ["one@example.com", "two@example.com"])
%Mail.Message{headers: %{to: ["one@example.com", "two@example.com"]}}
Mail.put_to(%Mail.Message{}, "one@example.com")
|> 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"}
render(message, renderer \\ Mail.Renderers.RFC2822)
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