Zoho Creator: Sendmail a list of attachments

Zoho Creator: Sendmail a list of attachments

What?
This is a very quick article on sending an email with Deluge which needs a dynamic number of files attached to it.

Why?
This came up during a call with another developer and it occurred to me that perhaps this isn't clearly documented. But there are tips found across the web just not specifically addressing this.

How?
Here is the code for a test function which downloads 2 files from a public domain, no user wall. The key here which the official documentation is missing is the .setParamName() but for those who have spent time to find this function, they'll already know this.

copyraw
void fn_Joel_Test()
{
	/***
		- tried with getUrl() but this doesn't work.
		- has to be an invokeUrl
		- set param name required
		- if file comes from a Creator form, no InvokeURL needed
			c_Form = Form[ID == 1234]; 
			r_Download1 = c_Form.myFieldWithFile;
	***/
	l_Downloads = List();
	r_Download1 = invokeUrl
    [
    	url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    	type: GET
    ];
	r_Download1.setParamName("file");
	l_Downloads.add(r_Download1);
	r_Download2 = invokeUrl
    [
    	url: "https://www.africau.edu/images/default/sample.pdf"
    	type: GET
    ];
	r_Download2.setParamName("file");
	l_Downloads.add(r_Download2);
	//
	sendmail
    [
    	from: zoho.adminuserid
    	to: "This email address is being protected from spambots. You need JavaScript enabled to view it."
    	subject: "Test File: List"
    	message: "This is just a test"
		attachments: file: l_Downloads
    ]
}
  1.  void fn_Joel_Test() 
  2.  { 
  3.      /*** 
  4.          - tried with getUrl() but this doesn't work. 
  5.          - has to be an invokeUrl 
  6.          - set param name required 
  7.          - if file comes from a Creator form, no invokeUrl needed 
  8.              c_Form = Form[ID == 1234]
  9.              r_Download1 = c_Form.myFieldWithFile; 
  10.      ***/ 
  11.      l_Downloads = List()
  12.      r_Download1 = invokeUrl 
  13.      [ 
  14.          url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" 
  15.          type: GET 
  16.      ]
  17.      r_Download1.setParamName("file")
  18.      l_Downloads.add(r_Download1)
  19.      r_Download2 = invokeUrl 
  20.      [ 
  21.          url: "https://www.africau.edu/images/default/sample.pdf" 
  22.          type: GET 
  23.      ]
  24.      r_Download2.setParamName("file")
  25.      l_Downloads.add(r_Download2)
  26.      // 
  27.      sendmail 
  28.      [ 
  29.          from: zoho.adminuserid 
  30.          to: "This email address is being protected from spambots. You need JavaScript enabled to view it." 
  31.          subject: "Test file: List" 
  32.          message: "This is just a test" 
  33.          attachments: file: l_Downloads 
  34.      ] 
  35.  } 

Yields
Zoho Creator: Send mail a list of attachments: Result

Category: Zoho :: Article: 856

Please publish modules in offcanvas position.