Send mail merge PDF using an email template

Send mail merge PDF using an email template

I'm looking to create a function that mail merges a PDF document, and sends it via email. The email is sent from an organization email address, and it has to be attached to the "emails" section of the record that triggers the function.

Originally, I used the task zoho.writer.mergeAndSend, but I wasn't able to customize the sender, nor attach the email to the CRM record.

I also used the "send mail" deluge task. The function worked ok, merging the PDF and sending the email, but I wasn't able to attach the email to the CRM record.

The last function I tested was using the send_mail task of the CRM API 3.0. This function allows me to select the company email as the sender, send the email using a template, and attach the email to the CRM record. The problem is, I'm not able to attach the PDF generated in a previous step using the task zoho.writer.mergeAndDownload. Below is the second part of the function. How can I attach the PDF to the email?

from_name = "Testing Name";
from_email = "";
module_name = "Deals";
org_email_address = true;
to_email = {{"email":""}};
//template_data = {"id":4434180000064050000};
template_data = {"id":4434180000064050000,"attachments:file":create_and_download};
email_subject = "Email Subject";
email_payload = {"data":{{"from":{"user_name":from_name,"email":from_email},"to":to_email,"org_email":org_email_address,"subject":email_subject,"mail_format":"html","template":template_data}}};
info email_payload;
send_mail_resp = invokeurl
url :"" + module_name + "/" + deal_id + "/actions/send_mail"
type :POST

                        Zoho Marketing Automation

                                Manage your brands on social media

                                        Zoho TeamInbox Resources

                                          Zoho DataPrep Resources

                                            Zoho CRM Plus Resources

                                              Zoho Books Resources

                                                Zoho Subscriptions Resources

                                                  Zoho Desk Resources

                                                    Zoho Projects Resources

                                                      Zoho Sprints Resources

                                                        Qntrl Resources

                                                          Zoho Creator Resources

                                                            Zoho WorkDrive Resources

                                                              Zoho Campaigns Resources

                                                                Zoho CRM Resources

                                                                • CRM Community Learning Series

                                                                  CRM Community Learning Series

                                                                • Tips


                                                                • Functions


                                                                • Meetups


                                                                • Kbase


                                                                • Resources


                                                                • Digest


                                                                • CRM Marketplace

                                                                  CRM Marketplace

                                                                • MVP Corner

                                                                  MVP Corner

                                                                • Word of the Day

                                                                  Word of the Day

                                                                      Design. Discuss. Deliver.

                                                                      Create visually engaging stories with Zoho Show.

                                                                      Get Started Now