Send Mail Scenarios

This topic illustrates the most common scenarios in which the sendmail function is invoked from Deluge Script. The sendmail Deluge function is used to send e-mails 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.
  1. How can I use the Email Id field in FormA as the To Address of the send mail task, in FromB
  2. How can I add records to a form using Send mail task?
  3. How can I send mail when a field value is modified
  4. How can I send mail to specific records using Deluge script
  5. How can I send mail with values selected in a multi-list field?
  6. How can I send mail to selected records in a view

 

1. How can I use the Email ID field in Form A as the "To Address" of the send mail task, in From B

Assume you want visitors to subscribe to a newsletter through a subscription form and later you want to send mail to the e-mail ids of subscribed users. The application should also allow subscribers to unsubscribe from the news letter. The sample application Subscribe to Newsletter illustrates this scenario. The application has three forms:

Subscription Form :

The form to subscribe to the newsletter. It has the Name and e-mailid fields to enable visitors to subscribe to the newsletter by specifying their e-mail ids. There is also one hidden field "isUnsubscribed" to check the status of each subscription. This field is hidden when the form is loaded. The on add -> on load script given below, hides the isUnsubscribed field, when form is loaded.

on  add
{
on load
{
hide isUnsubscribed;
}
}

Send Mail Form

This form is used by the owner to send mails to the subscribers mailing list. It has the Send decision check-box field which when set to "true" will send e-mails to the subscriber mailing list. This is achieved by adding on user input script to the Send field as given below.

Send
(
type = checkbox
defaultvalue = false
on user input
{
if (input.Send)
{
for each r in Subscription_Form [isUnsubscribed == false]
{
sendmail
(
To : r.EmailId
From : zoho.adminuserid
Subject : "Regarding subscription to our newsletter"
Message : "Your subscription is approved"
)
}
}
}

Code Explanation

if (input.Send) - The if statements will be executed if the Send decision check-box is set to true.

for each r in Subscription_Form [isUnsubscribed == false] - Here, isUnsubscribed is a Decision Check field and r is a variable that stores the records whose isUnsubscribed status is false.

sendmail - Send mail to the e-mail id specified in the row variable r.

Unsubscribe form

The form used to unsubscribe from the newsletter. This form contains the e-mailId field, using which the user unsubscribes from the newsletter. When a user submits his e-mailid, the on add -> on success script added to this form, updates the decision checkbox field isUnsubscribed in the Subscription form to true, as shown in the code given below:

on  add
{
on success
{
temp = Subscription_Form [EmailId == input.EmailId];
temp.isUnsubscribed = true;
}
}

Code Explanation:

temp = Subscription_Form [EmailId == input.EmailId];

-The above code will fetch records from the Subscription Form whose EmailId is equal to the EmailId specified in this form, and store it in a collection variable named temp.

temp.isUnsubscribed = true;

- The above code sets the isUnsubscribed field in the fetched record to true.

 

2. How can I add records to a form using Send mail task?

Every form in Zoho Creator has its own e-mail address. You can use this e-mail address in the Sendmail function to add a record to another form. Please refer the topic, Add records to a form using scripting for more information.

 

3. How can I send mail when a field value is modified

Assume you have a Feedback form with a Status field with values "Open" and "Closed". When a feedback/issue is solved, the staus is set to "Closed" by the team member and a e-mail is sent to the person who had raised the issue. To do this, we have to add an on update script to the Status field, as shown below:

Status
        (
            type  =  picklist
            values  =  {"Open",   "Closed"}
            defaultvalue  =  "Open"
            on update
{
if (input.Status == "Closed")
{
sendmail
(
To : input.Your_e-mailid
From : zoho.adminuserid
Subject : "Status of issue with subject " + input.Your_Comments
Message : "The issue is " + input.Status
)
}
}
)

 

4. How can I send mail to particular records using Deluge script

You can send mail to specific records in a form by using the sendmail Deluge syntax within a for each deluge statement. Refer the link Fetch a collection of records and iterate over them, for more information.

 

5. How can I send mail with values selected in a multi-list field?

Refer the topic Tips & Tricks -> Iterating Data in Radio buttons/check-boxes.

 

6. How can I send mail to selected records in a view

You can send mail to selected records in a view using Custom Actions. Refer the link Functions -> Custom Actions for more information.

Related Links

Deluge References - Form Actions
Deluge References - Field Actions
Deluge References - Send Mail