Send Mail

Overview

The sendmail function can be used to send emails from your zoho creator application. For example, you can invoke the sendmail function from the on success script to send mail when a record is successfully added to the database.

To avoid spam email messages, the From address in the sendmail function can be configured as either zoho.adminuser or zoho.loginuser and cannot be configured with any other address. The To address can be configured with any email id. If the to address remains the same for all the records, you can directly specify the address in the To field within quotes, for example "test@zoho.com". 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.

Syntax

sendmail
 [
     to       :  <string expression>
     From     : <string expression> 
     subject  : <string expression> 
     message  : <string expression> 
 ]

where,

  • to - the mail recipient
  • from - the admin user or the login user
  • subject - the text you want to display in the message subject
  • body - 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 to 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.

Note IconNote: The email sent will have the email id of the application owner or the email id of the login user, as the From address.

Example

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.

1. Form 'Employee' has the following fields: Name, Qualification, EmailID, TeamName, JoinDate
2. Write on add -> On success script, as given below:

for each x in Employee [JoinDate > '10-Jul-2007']
{
sendmail
(
To : x.EmailID
From : zoho.adminuser
Subject : "Meeting at 6:pm tomorrow"
Message : "As our CEO wants to address the new employees, you are requested to attend the meeting.<br>Thanks"
)
}

Code Explanation

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

Related Links

Tips & Tricks -> Send Mail Scenarios
Tips & Tricks -> Customizing Email Messages