SMTP emails not filling "main" content?

410 views
Skip to first unread message

Gordon McNaughton

unread,
Sep 27, 2012, 4:41:44 PM9/27/12
to mandrill-a...@googlegroups.com
Hey all,

I'm having trouble getting Mandrill to fill the body of my email into a template when sending through SMTP.

Per the docs (http://help.mandrill.com/entries/21688056-using-smtp-headers-to-customize-your-messages#templates) on the X-MC-Template header, I have a template called "Sample":

Begin
<div mc:edit="main">
     This should get replaced
</div>
End

Sending an email through my Rails app shows this in the logs (note the X-MC-Template header):

Subject: Sample email with template: Sample
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
X-MC-Template: Sample

Sample email body.

This results in the following email:

Begin
End

Where did the "Sample email body" text go?  Wasn't it supposed to get filled in to mc:edit="main"?  Choosing 'show original' shows the following (headers omitted):

--_av-fa636a12-4996-423c-ad0c-e6ce260ad7dc
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Sample email body.

--_av-fa636a12-4996-423c-ad0c-e6ce260ad7dc
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
Begin
<div></div>
End<img src="http://mandrillapp.com/track/open.php?u=10518691&id=93367431e5ca4bcf9db301fc7fd7493d&tags=1084829,1108569,1109821" height="1" width="1">
--_av-fa636a12-4996-423c-ad0c-e6ce260ad7dc--

The body of my email made it into the text version, but why not the html?

I've tried X-MC-Template: Sample, Sample|main, and other block names to no avail.  Any idea what's going on?

Thanks!
-Gordon

Gordon McNaughton

unread,
Sep 27, 2012, 6:15:24 PM9/27/12
to mandrill-a...@googlegroups.com
Okay, I think I discovered my mistake.

I was sending emails from a test mailer which used :body => "..." to set the body text.

# Does not work :(
mail({ :subject => "Sample email", :body => "Sample email body." })
headers['X-MC-Template'] = "Sample"

This caused the mail to be sent as "Content-Type: text/plain; charset=UTF-8".  Taking out the explicit :body => and letting Rails generate the mail from a view erb changed that to "Content-Type: text/html; charset=UTF-8", and the value started getting filled in.

# Works!
mail({ :subject => "Sample email" }) # no :body
headers['X-MC-Template'] = "Sample"

X-MC-Autotext starts getting respected, too, rather than just using the exact text of the smtp body.

Sorry for the confusion!
-Gordon
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages