Send Page as PDF Attachment via Email

Send Page as PDF Attachment via Email

Requirements

Schedule an email to send a Zoho Creator page as a PDF attachment at defined time intervals using Deluge's sendMail task.

Use Case

To support customer engagement and business promotion, an organization uses the Pages feature in Zoho Creator to create a newsletter featuring customer testimonials, metrics, and product sales count. This newsletter will be shared with subscribed customers on the first day of every month via email in the form of PDF attachments.
Note: The page will be downloaded as a PDF via API and sent as an email attachment. 

Steps to Follow

  1. Create a form with the following details to add customer details.

    Form

    Form Link Name

    Field Type

    Field Name

    Field Link Name

     

     

    Customer Details

     

     

    Customer_Details

    Name

    Customer Name

    Customer_Name

    Email

    Email

    Email

    Phone

    Phone

    Phone

    Address

    Address

    Address

    Decision box

    Subscribe to monthly newsletter

    Subscribe_to_monthly_newsletter

  2. Create a page named Newsletter and customize it as necessary.
  3. Note: It is not recommended to have embedded forms or reports in the page, as it restricts the the ability to download the page through the API.

  4. Publish the Newsletter page that you want to send as attachment.
  5. Note: Kindly refrain from including sensitive information on this page, as it will be publicly accessible to everyone via permalink upon publishing.
  6. Create a schedule workflow to run on the first day of every month. Select the start date and time as the first day of a month and time as per your preference, here we have set date as 01-Dec-2023 and Time as 07:00:00 Hrs. Set the frequency of the workflow to run Monthly and name it as Email Newsletter.

  7. Click Add New Action and select Deluge Script. Add the below script to the editor and save.
Note: Mail can be sent only to a maximum of 340 addresses at a time through Deluge send mail task through the below code. For handling more than 340 addresses, proceed to the next snippet.
  1. Utilize the below script to send mail to less than 340 email addresses.
  1. //Download the Creator page as PDF file using the invokeurl task.
  2. fileResp = invokeurl
  3.   [
  4.    url :"https://creatorapp.zohopublic.com/export/<adminUserName>/<appLinkName>/pdf/pageLinkName>/<encryptedKey>?isc5page=true"
  5.    type :GET
  6.   ];
  7. //Fetch the email addresses of all customers subscribed to newsletter.
  8. emailList = Customer_Details[Subscribe_to_monthly_newsletter = true].Email.getAll();
  9. //Send mail to all email address in the list, including the downloaded PDF file as an attachment.
  10. sendmail
  11.   [
  12.    from :zoho.loginuserid
  13.    to :emailList
  14.    subject :"Zylker Corporation Newsletter"
  15.    message :"Greetings form Zylker Corporation, We are thrilled to share our newsletter of November 2023 with you. Have a great day"
  16.    Attachments :file:fileResp
  17.   ] 

.

  1. Utilize the below provided code when handling email lists containing more than 340 email addresses.
  1. //Download the Creator page as PDF file using the invokeurl task.
  2. fileResp = invokeurl
  3.   [
  4.    url :"https://creatorapp.zohopublic.com/export/<adminUserName>/<appLinkName>/pdf/<pageLinkName>/<encryptedKey>?isc5page=true"
  5.    type :GET
  6.   ];
  7. //Fetch the email addresses of all customers subscribed to newsletter.
  8.  emailList = Customer_Details[Subscribe_to_monthly_newsletter = true].Email.getAll();
  9.  batchSize = 340;   //To determine the number of email addresses to include in each batch of emails.
  10.  emailBatch = List();   //Empty list to store the email addresses for each batch. 
  11.  index = 0;    //Counter to keep track of the number of email addresses that have been added

  12. // Iterate over the list of email addresses and send email in batches. 
  13. //If the index reaches the maximum batch size, send the email to the complete batch of 340 email addresses and reset all variables. Otherwise, add the current email address to the emailBatch and increment the index variable until the batch is complete. 

  14.  for each  email in emailList
  15.  {
  16.   if(index >= batchSize)
  17.   {
  18.   sendmail
  19.   [
  20.    from :zoho.loginuserid
  21.    to :emailBatch
  22.    subject :"Zylker Corporation Newsletter"
  23.    message :"Greetings form Zylker Corporation, We are thrilled to share our newsletter of November 2023 with you. Have a great day"
  24.    Attachments :file:fileResp
  25.   ] 
  26.    emailBatch = List();
  27.    index = 0;
  28.   }
  29.   emailBatch.add(email);
  30.   index = index + 1;
  31.  }
  32. //If there are any remaining email addresses after the last batch, send them as final batch of emails.
  33.  if (emailBatch.size() > 0)
  34.  {
  35.   sendmail
  36.   [
  37.    from :zoho.loginuserid
  38.    to :emailBatch
  39.    subject :"Zylker Corporation Newsletter"
  40.    message :"Greetings form Zylker Corporation, We are thrilled to share our newsletter of November 2023 with you. Have a great day"
  41.    Attachments :file:fileResp
  42.   ]
  43.   }
Substitute the variables in the preceding script with pertinent data, as indicated in the table provided below:

<adminUserName>

is the username of the person who owns the application.

<appLinkName>

is the link name of the application.

<pageLinkName>

is the link name of the page that needs to be downloaded via API.

<encryptedKey>

is the unique key that is generated while publishing the page. It can be located within the URL of the published page. For example, in the following publish URL: https://creatorapp.zohopublic.com/zylker/customer-relationship-manager/page-perma/dashboard/HPtR6ZeWSEJW4TwCS2rJOCCg2k1QJZAmrngnbhVECqCWtER8FmDzEdspDwMySSsAMR9gd6PW79jNwa3gp4kjvfez9UJCp4SrmBfU

the encrypted key is as follows: HPtR6ZeWSEJW4TwCS2rJOCCg2k1QJZAmrngnbhVECqCWtER8FmDzEdspDwMySSsAMR9gd6PW79jNwa3gp4kjvfez9UJCp4SrmBfU

 

See How it Works


  1. Understand publishing a page
  2. invokeURL
  3. sendMail
  4. Understand Schedules