Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandrill API Templating

I'm using Mandrill's Ruby API Gem and have the follow simple template for testing:

<html>

    <body>
        <h1 mc:edit="header">testastic</h1>
        <hr/>
        <br/><br/>
        <div mc:edit="main_section"></div>
        <hr/>
        <div mc:edit="footer"></div>
    </body>
 </html>

Following the example on Heroku's guide I have the follow Ruby code:

require 'mandrill'
  m = Mandrill::API.new
  rendered = m.templates.render 'test-template', [{:header => 'some header text', :main_section => 'The main content block', :footer => '<h3>asdf</h3>'}]

  mail(:to => "Jayson Lane <[email protected]>", :subject => "Test Email") do |format|
       format.html { rendered['html'] }
       #format.text { render "test" }
  end

This works great and the email sends my template just fine, however, it doesn't replace the template mc:edit variables. Am I missing something?

like image 456
Jayson Lane Avatar asked Feb 26 '13 16:02

Jayson Lane


People also ask

How do I make a Mandrill template?

Use the drag and drop template editor to make the desired template, then copy the code and paste it into the Mandrill template editor. Or connect your Mandrill and Mailchimp accounts and let Mandrill copy your templates over for you.

What is Mandrill API?

Mandrill is a transactional email API for MailChimp users. It's reliable, powerful, and ideal for sending data driven emails, including targeted e-commerce and personalized one-to-one messages.

How do I send an email using Mandrill API?

Click on “Launch Mandrill”. Click on “Setup your sending domain” button and add your domain name. It will ask you the email associated with the domain name in order to verify it. It will send you an email, click on the link to verify your account.

Does MailChimp have responsive templates?

Mailchimp's campaign templates use responsive design to adjust the layout of your campaign to look great on any device. But, not every device handles responsive code the same way, which can make your campaign look a little different on mobile than in a web browser.

How do I get Started with the mandrill API?

Get official API clients (and documentation) and test each call right in your browser using Mandrill's executable API docs. Start sending emails in a matter of minutes with Mandrill's quick-start SMTP Integration. Explore official and 3rd party wrappers and integrations to streamline your connection to Mandrill.

Should I use an email templating service instead of Mandrill?

Feb 21 '15 at 17:56 You might want to consider an email templating service, instead of interfacing with Mandrill directly. Checkout sendwithus.com or customer.io. Both make it much easier to manage variables, and work well with C#. – bvanvugt

What is Mandrill?

Mandrill is a scalable and affordable email infrastructure service. Whether you're just getting started, have some questions, or are looking for a quick reference, we've got you covered. What you need to know before you begin. From the basics to FAQs, learn how Mandrill can help further your email experience.


1 Answers

You need to construct a hash for each element you're trying to replace. For instance, I have this inside of a template:

   <h3 mc:edit="plan_info_name"> </h3>
   <span mc:edit="plan_info_description"> </span>
   <span mc:edit="plan_info_benefits"> </span>

And this on the mailer:

mandrill.messages.send_template(template,[
    {
     :name => 'plan_info_name',
     :content => extra[:membership_info].name
    },
    {
     :name => 'plan_info_description',
     :content => extra[:membership_info].long_description   
    },
    {
     :name => 'plan_info_benefits',
     :content => benefits_list 
    }
  ....
like image 82
fmendez Avatar answered Oct 17 '22 01:10

fmendez