Search code examples
bashmailgun

How to attach a file to Mailgun via command line?


There is nice example at here that illustrates how to send an email from command line. My problem is I don't understand how attachment works. This is the sample code:

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Excited User <YOU@YOUR_DOMAIN_NAME>' \
    -F to='[email protected]' \
    -F cc='[email protected]' \
    -F bcc='[email protected]' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    --form-string html='<html>HTML version of the body</html>' \
    -F attachment=@files/cartman.jpg \
    -F attachment=@files/cartman.png

When I remove attachments I receive the message I sent. However I'm not able to receive it when I use attachment. So my questions is:

  1. What is @files?
  2. If I want to send an image from my desktop what should I pass to attachment?

Solution

  • Ok, I just found it. files is fictional folder :)

    You can just cd to desktop. Then add attachment like this:

    -F [email protected]
    

    Thanks to this doc: http://blog.mailgun.com/mailgun-api-2-0-forget-mime/