mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM
https://dev.mailjet.com
Other
130 stars 72 forks source link

http://dev.mailjet.com/guides Ruby examples dosen't match with the gem #49

Closed UgoMare closed 9 years ago

UgoMare commented 9 years ago

I'm trying to send email with attachment through the api.

variable = Mailjet::Send.create(
        from_email: "pilot@mailjet.com",
        from_name: "Mailjet Pilot",
        subject: "Your email flight plan!",
        text_part: "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
        html_part: "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
        recipients: [{'Email'=> 'passenger@mailjet.com'}],
    attachments: [{'Content-Type' => 'text/plain', 'Filename' => 'test.txt', 'content' => 'VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK'}])

The example in the gem say

Mailjet::MessageDelivery.create(from: "me@example.com", to: "you@example.com", subject: "Mailjet is awesome", text: "Yes, it is!")

But I don't know how to join an attachment.

And how can I add an attachment with mailjet api and ActionMailer.

attachments['file.txt'] = { mime_type: 'application/x-gzip', content: File.read('public/file.txt') }
mail to: email, subject: 'test'

The email is delivered without the attachment.

WeshGuillaume commented 9 years ago

Hey @UgoMare !

Sorry about that. The API guides was a little bit ahead. I have pushed a fix on master to make you code works:

variable = Mailjet::Send.create(
        from_email: "pilot@mailjet.com",
        from_name: "Mailjet Pilot",
        subject: "Your email flight plan!",
        text_part: "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
        html_part: "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
        recipients: [{'Email'=> 'passenger@mailjet.com'}],
    attachments: [{'Content-Type' => 'text/plain', 'Filename' => 'test.txt', 'content' => 'VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK'}])

Attachment through the ActionMailer via the Mailjet Api is currently not supported, I am working on that.

Please let me know if the Send snippet works on your side ! :)

UgoMare commented 9 years ago

Even after the update, it still doesn't works. I think the problem is not about the pluralisation of attachments in the commit: https://github.com/mailjet/mailjet-gem/commit/d1ef23b4059947fec0ecfbd3dd4bb9b0691023d3 but the class Mailjet::Send seems to be not accessible.

Mailjet.constants.select {|c| Class === Mailjet.const_get(c)}
WeshGuillaume commented 9 years ago

Did you clone the repo ? It actually works on my side.

The update is not on ruby gem yet, you need to clone the last update on github and reference it in your gemfile

gem "mailjet", :path => '/path/to/mailjet-gem'
[:ApiError, :Connection, :MethodNotAllowed, :MessageDelivery, :Aggregategraphstatistics, :Apikey, :Apikeyaccess, :Apikeytotals, :Apitoken, :Axtesting, :Batchjob, :Bouncestatistics, :Campaign, :Campaignaggregate, :Campaigngraphstatistics, :Campaignoverview, :Campaignstatistics, :Clickstatistics, :Contact, :Contact_getcontactslists, :Contact_managecontactslists, :Contact_managemanycontacts, :Contactdata, :Contactfilter, :Contacthistorydata, :Contactmetadata, :Contactslist, :Contactslist_managecontact, :Contactslist_managemanycontacts, :Contactslistsignup, :Contactstatistics, :Csvimport, :DNS, :DNS_check, :Domainstatistics, :Eventcallbackurl, :Geostatistics, :Graphstatistics, :Listrecipient, :Listrecipientstatistics, :Liststatistics, :Manycontacts, :Message, :Messagehistory, :Messageinformation, :Messagesentstatistics, :Messagestate, :Messagestatistics, :Metadata, :Metasender, :Myprofile, :Newsletter, :Newsletter_detailcontent, :Newsletter_schedule, :Newsletter_send, :Newsletter_status, :Newsletter_test, :Newsletterblock, :Newsletterproperties, :Newslettertemplate, :Newslettertemplateblock, :Newslettertemplatecategory, :Newslettertemplateproperties, :Openinformation, :Openstatistics, :Parseroute, :Preferences, :Send, :Sender, :Senderstatistics, :Toplinkclicked, :Trigger, :User, :Useragentstatistics, :Widget, :Widgetcustomvalue]
WeshGuillaume commented 9 years ago

Hey ! Did you manage to make it work on your side ?

Guillaume.

UgoMare commented 9 years ago

Yes thanks.