The sendmail task can be used to send emails from your Zoho Creator application. For example, you can invoke the sendmail function from Form Actions -> on add -> on success script to send mail when a new record is successfully added to the database. To avoid spam email messages, if the From: address is not a zoho.adminuserid or zoho.loginuserid, the To: address can only be zoho.adminuserid and the sendmail task cannot have any CC: or BCC: address.
You can also directly specify the address in the To: field within quotes, for example "email@example.com", if the to address remains the same for all the records. To send mail to the email ids specified in each record, use the input.<field_name_of_type_email>, which will replace the value of the email id in each record. The subject and message fields can be customized to suit the user requirements. Again, the input.<field_name> can be used to substitute the value of the record.
From : <string expression>
To : <string expression>
Subject : <string expression>
Message : <string expression>
- To- the mail recipient
- From- the sender
- Subject - the text you want to display in the message subject
- Message- the text you want to display in the message body
- <string expression> - deluge expression evaluating to valid email address in case of From and To and any valid string in case of subject and message. subject and message are optional parameters. To know in detail about the expressions in Deluge, refer to Expressions.
- The email sent will have the email id of the application owner or the email id of the login user, as the From address. If the From: address is not a zoho.adminuserid or zoho.loginuserid, the To: address can only be zoho.adminuserid and the sendmail task cannot have any CC: or BCC: address.
Using Script Builder
You can configure to send e-mail message with form data either from the Form GUI or by adding Deluge Script with the Send mail task.
- To configure email notifications from the Form GUI, refer the topic, Configure email notifications from GUI. The email notifications configured from the Form GUI will be displayed as a script in the Form Actions -> on add -> on success block of the Script tab.
- To configure email notifications with form data by adding Deluge Script, use the input.formdata variable in On Add -> On Success or On Edit -> On Success script.
Steps to add the Send mail script using Script Builder:
- Select the Script tab.
- Select the required Form from the Select Form list-box.
- Select the Form action to invoke the script. For example, if you want to send mail when a record is submitted, select the form action on Add -> On Success.
- Next, select the Deluge task that needs to be executed. To send mail, drag-n-drop the send mail task to the editor area.
- Move mouse over the task and click on the Edit option, as shown in the screen-shot below.
- The Send Mail screen is displayed, wherein you specify the From, To, Subject and Message.
- To send mail with formdata, specify the message as shown in the below format selecting the Rich text tab.
- Click Done to update the configurations to the script builder.
- Click Save Script to save the script. Now, when a record is submitted, the configured email is sent to the specified To address with the Form data. A sample format of the email is shown below:
The CEO of a company wants to address all the new employees who have joined after certain date say, '10-jun-2007' . We have to mail all these new employees. Lets see how we can achive this.
- Form 'Employee' has the following fields: Name, Qualification, EmailID, TeamName, JoinDate
- Write on add -> On success script, as given below:
for each x in Employee [JoinDate >'10-Jul-2007']
To : x.EmailID
From : zoho.adminuserid
Subject : "Meeting at 6:pm tomorrow"
Message : "As our CEO wants to address the new employees, you are requested to attend the meeting.
for each x in Employee [JoinDate > '10-Jul-2007'] - Fetches the records from the Employee form with the given criteria and iterates over each record, to send mail to the EmailID of each record. Here 'x' is the instance variable that will represent a single record in each iteration.
sendmail - The deluge function to send mail
x.EmailID - Refers to the emailid of each record