我想使用 Mailjet 发送订单确认电子邮件。
首先,我安装了 Gem 并配置为Mailjet 指南
gem 'mailjet'
初始化程序/mailjet.rb
Mailjet.configure do |config|
config.api_key = '<my_api_key>'
config.secret_key = '<my_secret_key>'
config.default_from = '<my_email>'
end
配置/应用程序.rb
config.action_mailer.delivery_method = :mailjet_api
这是我的控制器中的操作
def send_email_reserved
email = { :from_email => "<my_from_email>",
:from_name => "Dona Sky",
:subject => "Hello",
:text_part => "Hi",
:recipients => [{:email => "<my_to_email>"}] }
test = Mailjet::Send.create(email)
p test.attributes['Sent']
end
当我调用该操作时,它显示了错误
NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}>
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in `type_for_extension'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in `type_for_extension'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block (2 levels) in stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `map'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block in stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `each'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `inject'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in `make_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in `initialize'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:67:in `handle_api_call'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:47:in `post'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/resource.rb:215:in `save'