Proof of Concept: Google Docs Mail Merge Form with Text and HTML #wordpress

I needed a way to be able to shamelessly plug the posts I recently bundled into the booklet “Write Something” again.In a similar way to the last time I did it in Proof of Concept: Google Docs Mail Merge Form
As I explained before I have set up a system to automatically mail somebody when the enter their address in the form, my issue was that I wanted to add a unique blogpost which they would only be able to get by signing up. Naturally I wanted to style it in the same way the posts are styled in this blog. Again I turned to the documentation, specifically the Class MailApp which I was using to send the mail. Using this documentation I had a starting point. I wanted three changes to the current script:
- keep the plain text
- add HTML message
- add inline images
First I created a new function to practice in called inlineImage in the Script Editor and a template to send in B2. The inline image retrieval is easily done by changing the example script to include the image I wanted te retrieve, and remembering to also edit the template image tag to refer to cid:writeSomeBlob rather than the true url. This embeds the image in the mail, and often means it passes through mail display filters.
And I needed to pass the variables I wanted to use to the new inlineImage function which could replace my call to MailApp.sendEmail in the original code.
function inlineImage(to,template) { var writeSomeBlob =
UrlFetchApp.fetch("http://farm4.static.flickr.com/3169/3109259359_550b7d1a32_m.jpg").
getBlob().setName("writeSomeBlob"); // fetch image to embed
MailApp.sendEmail(
to,
template.getRange("A1").getValue(), // mailaddress
template.getRange("A2").getValue(), // plain text
{ htmlBody:
template.getRange("B2").getValue(), // html
inlineImages:
{
writeSome:writeSomeBlob // embed image
}
}
);
}

Finally you replace the call to MailApp.sendEmail in sendEmails with a call to inlineImage.
inlineImage(rowData.mailAddress,templateSheet);
Read previous article in series…
And ensure that the Triggers functionality is still pointing to sendEmails. (Goto the menu, select the current project’s triggers… and verify the trigger which should be run On form submit.)

Image source: Search Engine People
















It’s really useful for me! Thanks for infomation.
fat cow hosting
March 12, 2012 at 2:39 pm