Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template defaults overridden #117

Open
chrisbloom7 opened this issue Apr 22, 2016 · 6 comments
Open

Template defaults overridden #117

chrisbloom7 opened this issue Apr 22, 2016 · 6 comments

Comments

@chrisbloom7
Copy link

chrisbloom7 commented Apr 22, 2016

I have some template defaults defined in Mandrill for a template. In my mailer I set default view_content_link: true but that seemed to override the template defaults for the from and from_name and the email was sent from "[email protected]". Interestingly, the default subject was not overwritten even though I didn't specify one in my mailer. I would expect that setting one default would not override the others that weren't specified.

class RewardSurveyTokenInvitationMailer < MandrillMailer::TemplateMailer
  default view_content_link: true

  def invite(company:, users:)
    invitees = users.map { |user| { email: user.notification_email, name: user.name } }

    mandrill_mail(
      template: 'custom-rewards-solicitation',
      to: invitees,
      vars: {
        'COMPANYNAME' => company.name,
        'COMPANYLOGO' => company.settings.try(:email_header_logo)
      },
      view_content_link: true,
      important: true,
      inline_css: true,
      track_opens: true,
      track_clicks: true,
      auto_text: true,
      recipient_vars: users.map do |user|
        { user.notification_email =>
          {
            'RWTOKEN' => reward_surveys_url(token: user.reward_survey_token),
            'FNAME' => user.first_name
          }
        }
      end,
      tags: %w(custom-rewards-solicitation)
     )
  end
end

template-defaults

rejected-email

Removing the default restored the default template values

@renz45
Copy link
Owner

renz45 commented Apr 22, 2016

I'm guessing it has something to do with this: https://github.com/renz45/mandrill_mailer/blob/master/lib/mandrill_mailer/arg_formatter.rb#L72

Looks like we send the entire message object, likely with a bunch of nil values, I wonder if that overwrites default values set in the mandrill gui?

@renz45
Copy link
Owner

renz45 commented Apr 22, 2016

If you don't mind, could you try something really quick and see if it fixes the issue? I no longer have a mandrill account. If it does I can make the changes in the gem quick.

Where ever you are calling RewardSurveyTokenInvitationMailer.invite(...).deliver add this code right before:

new_message = {}
RewardSurveyTokenInvitationMailer.message.each_pair do |k,v|
  if v
    new_message[k] = v
  end
end
RewardSurveyTokenInvitationMailer.message = new_message

I think this should remove all the nil values and their keys. If this works I'll change that arg formatter method to do the same. Thanks again!

@chrisbloom7
Copy link
Author

Thanks for investigating. I’m traveling this weekend, but I’ll try your fix
next week and let you know

On Fri, Apr 22, 2016 at 9:31 AM, Adam Rensel [email protected]
wrote:

If you don't mind, could you try something really quick and see if it
fixes the issue? I no longer have a mandrill account. If it does I can make
the changes in the gem quick.

Where ever you are calling
RewardSurveyTokenInvitationMailer.invite(...).deliver add this code right
before:

new_message = {}RewardSurveyTokenInvitationMailer.message.each_pair do |k,v|
if v
new_message[k] = v
endendRewardSurveyTokenInvitationMailer.message = new_message

I think this should remove all the nil values and their keys. If this
works I'll change that arg formatter method to do the same. Thanks again!


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#117 (comment)

@chrisbloom7
Copy link
Author

Haven't forgotten about this. Working on our Mandrill integration this week and will test this once we're properly configured again.

@RossStein
Copy link

RossStein commented May 9, 2017

The template defaults in Mandrill for From Address and From Name do not appear to be accessible because the default for From Address is [email protected]. This happens with view_content_link: true and view_content_link: false. Is it possible to change the default to look in the Mandrill template defaults or have the template defaults override [email protected]?

@renz45
Copy link
Owner

renz45 commented May 10, 2017

Just curious, did anyone try my above fix? If that works I can change the formatter to do that internally, which should fix the issue. If someone comes up with another, more preferable fix feel free to make a PR and I'll merge it in. I don't work with mandrill at all anymore, so testing api level things is a bit time consuming for me at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants