Search code examples
ruby-on-railsrubyemailmailjet

Rails : Send email with Mailjet Api V3


I try to send an email with the new mailjet api (v3). Here is my config :

gemfile

gem 'mailjet'

config/initializers/mailjet.rb

Mailjet.configure do |config|
  config.api_key = '<my api>'
  config.secret_key = '<my_psw>'
  config.default_from = 'mail@conicrea.com'
  config.domain = 'localhost'
end

mailer.rb

  def send_unsubscribe(user)
    @user = user
    @to = "paul@conicrea.com"
    @from = "mail@conicrea.com"

    mail(to: @to, from: @from, subject: "TTP Tork - Demande de désinscription") do |format|
      format.html
    end
  end

user.rb

def send_unsubscribe
  Mailer.send_unsubscribe(self).deliver
end

u.send_unsubscribe

In log, the mail seems to be create en send but there is no email in my mailbox and in mailjet...


Solution

  • It seems like you're looking to use Mailjet's SMTP relay. Here is how to configure it this way:

    Start off by changing this line config.domain = 'localhost' to your registered domain name rather than just 'localhost'.

    Next, add this config.action_mailer.delivery_method = :mailjet_smtp to your application.rb file

    Not entirely sure which hosting service you are using, but check out this link. It shows you how to configure your SPF and DKIM settings for each hosting service to accommodate Mailjet.