-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attachments: Support file data in attachment struct + mailgun attachment support #292
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ defmodule Bamboo.Email do | |
assigns: %{}, | ||
private: %{} | ||
|
||
alias Bamboo.Email | ||
alias Bamboo.{Email, Attachment} | ||
|
||
@address_functions ~w(from to cc bcc)a | ||
@attribute_pipe_functions ~w(subject text_body html_body)a | ||
|
@@ -203,7 +203,33 @@ defmodule Bamboo.Email do | |
end | ||
|
||
@doc ~S""" | ||
Adds an attachment to the email | ||
Adds an data attachment to the email | ||
|
||
## Example | ||
put_attachment(email, %Bamboo.Attachment{}) | ||
|
||
Requires the fields filename and data of the %Bamboo.Attachment{} struct to be set. | ||
|
||
## Example | ||
def create(conn, params) do | ||
#... | ||
|> put_attachment(%Bamboo.Attachment{filname: "event.ics", data: "BEGIN:VCALENDAR..."}) | ||
#... | ||
end | ||
""" | ||
def put_attachment(%__MODULE__{attachments: attachments} = email, %Attachment{filename: nil}) do | ||
raise "You must provide a filename for the attachment." | ||
end | ||
def put_attachment(%__MODULE__{attachments: attachments} = email, %Attachment{data: nil}) do | ||
raise "The attachment must contain data." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you include the attachment in both error message so that it's easier to see what they passed in? raise "The attachment must contain data, instead got: #{inspect attachment}" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Done. Also cleaned up a bit. There were some warnings about not used variables. |
||
end | ||
def put_attachment(%__MODULE__{attachments: attachments} = email, %Attachment{} = attachment) do | ||
%{email | attachments: [attachment | attachments]} | ||
end | ||
|
||
@doc ~S""" | ||
Adds an file attachment to the email | ||
|
||
## Example | ||
put_attachment(email, path, opts \\ []) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!