chrismccord / mailgun

Elixir Mailgun Client
MIT License
194 stars 95 forks source link

How to send attachments? #27

Closed optikfluffel closed 3 years ago

optikfluffel commented 8 years ago

Hi :) It would be nice to have an example (or test case to look at) on how to send an email with some files attached.

vysakh0 commented 8 years ago

@optikfluffel We could send multiple attachments as a list of maps (even keyword list) with keys path & filename

def send_greetings(user, file_path) do
    send_email to: user.email,
               from: @from,
               subject: "Happy b'day",
               html: "<strong>Cheers!</strong>"
               attachments: [%{path: file_path, filename: "greetings.png"}]
end

In my case I wanted to send invoice pdf on the fly in my mails to users, so didn't want to create a temporary file and send it part of the attachments. So, did this https://github.com/vysakh0/mailgun/commit/51cf14704fa3fcf61e88c5d3331451388f982fff

optikfluffel commented 8 years ago

@vysakh0 cool, thanks a ton, I also wanted to send something without writing it to disk first, perfect! :grin: I wonder if you should make a PR to make this a feature, I'm not sure wether we're the only ones wanting to send attachments this way or not. Any thoughts on this @chrismccord?

chrismccord commented 8 years ago

yes, PR please!

vysakh0 commented 8 years ago

Thanks :+1: Done :smile: https://github.com/chrismccord/mailgun/pull/28

tralamazza commented 8 years ago

Anyone tried sending binary attachments, like a pdf for instance? I'm having trouble.

httpc seems stuck while trying to send a pdf. (using 0.1.2)