Automatic responses to emails
In this tutorial we will demonstrate how to send automatic email replies with todo4teams.
If your ticketing system converts incoming emails into tickets and routes them through your service structure, it makes sense to send the customer a direct reply confirming receipt of their message and stating the ticket number under which their request will be processed.
To do this, proceed as follows:
- Log in to todo4teams with the Administrator or Super Administrator role
- Switch to the “Mailboxes” navigation point
- Select the email account for which you want to set up an automatic reply
- The mailbox configuration editor opens automatically
- Switch to the Scripts tab and then to the “Receive Action”
In the text box, paste the script given below:
The Script:
var email = message.getFrom()[0].getAddress();
var footer = task.source.sourcemailbox.footer;
var text = "<html><head></head><body><p>Dear madam or sir,<br/><br/>\n";
text += "we herewith confirm having received your message.<br/><br/>";
text += "We will check your request and get in touch with you shortly.<br/>\n";
text += "Please note your ticket id for further processing: "+id+"<br/><br/>\n";
text += "With kind regards<br/>\n";
text += "Service Team<br/></p><br/>\n";
text += "</p><br/>\n";
text += "Subject of your request:<br/><pre>"+ message.getSubject()+"</pre>";
text += "\n<br/><br/>"+footer+"</body></html>";
helper.sendmail(
task.source.sourcemailbox.emailAddress, // sender email address
"Your request to "
+task.source.sourcemailbox.emailAddress+" (ID: "+id+")", // subject
text, // message
email, // addressee
null, // cc
null, // bcc
"support@bergener-partner.de", // reply to
true // html formatted message
);
This expression determines first the email-address of the sender:
The message-Object is the received email-message as a java-object. It possesss a list of from-addresses and writes the first value (in practice there is exactly one) into the variable email.
We want to add the footer of the email-account to the automatic response-email, therefore we add the corresponding value to another variable.
This variable is determined by the attribute footer of the email-account which has sent us the message, therefore task.source.sourcemailbox.footer.
The message content is then put together into the variable text. We will write the email in HTML-format for a more pleasing presentation to the receiver.
There will be used the ID of the ticket (extracts the ID as in the first line), the subject of the received message message.getSubject() and the above-identified footer.
Then the function helper.sendmail() is executed in order to send the message. Please note that there are quite a number of call formats for helper.sendmail() (with or without attachments, with and without CC, BCC for example). For more details please refer to the API documentation on the main page of your todo4teams installation.
During the execution of helper.sendmail() the following parameters are submitted:
- the email-address with the sender has sent the message. If you have here a string-constant (eg "service@mycompany.com"), it must be written exactly as the address as it is configured in todo4teams.
- the subject of the message
- the message itself in HTML-format
- the destination address/addressee
- the CC-address (here suppressed by zero)
- the BCC-address (here suppressed by zero)
- the ReplyTo-address
- true as the attribute that the e-mail should be sent in HTML-format
Save the configuration of the email-account. Please click "Validate" to perform a syntax check and remove any errors.
Test the script by sending a message to this mailbox in your e-mail program. todo4teams sends and receive emails every two minutes, so it can take up to four minutes until the automatic response arrives back at you.
Modify the sample code according to your needs. Style the HTML-code for example with the HTML-style-construct or embed an image in order to adapt the messages to the corporate design of your company.