Automatic responses to emails with existing ticket-IDs
In the previous tutorial on automatic reply emails, we already explained the basics of automatically sending a reply email when jobs arrive.
At this point, we would like to familiarize you with more advanced options, in particular how to handle reply-to addresses, the option of configuring the footer using HTML and structuring the reply text.
As usual, you will find all the options for structuring a reply email in the "Receive Action" tab of the mailbox in question.
In a first step we define the variables required below and fill them with content:
var toEmail = message.getFrom()[0].getAddress();
var css=helper.getServerPropertyByName('emailCss');
var footer = task.source.sourcemailbox.footer;
var emailreplyto = task.getProperty("EMAILREPLYTO");
The variables now contain the following:
- "id" is the ID of the ticket in todo4teams as a reference for the customer under which number the ticket is being processed.
- "toEmail" is the sender's email address
- "css" is filled with the content of the server property "emailCss" and defines the CSS style of the reply email.
- "footer" reflects the content of the signature text in the basic data of the mailbox (first tab in the overview).
- "emailreplyto" reflects the content of the reply-to address that the sender may have entered separately when sending the email. In Mozilla Thunderbird, for example, this is called "Reply to".
The reply-to address is automatically placed in the address field, provided the sender has set one, when a ticket is processed.
Now we define the text that we want to send. The example text sends a response in both German and English and uses the contents of the variables "id" and "footer" defined above.
text += "hiermit bestätigen wir den Erhalt Ihrer Nachricht.<br/><br/>";
text += "Wir werden Ihr Anliegen sorgfältig prüfen und uns schnellstmöglich bei Ihnen melden.<br/>\n";
text += "Bei Rückfragen geben Sie bitte die Bearbeitungsnummer "+id+" im Betreff an.<br/><br/>\n";
text += "Mit freundlichen Grüßen<br/>\n";
text += "Muster und Sohn AG<br/></p>\n";
text += "<hr/><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 += "Muster und Sohn Ag<br/></p><br/>\n";
text += "</p><br/>\n";
text += "Betreff Ihrer Nachricht / Subject of your request:<br/><pre>"+ message.getSubject()+"</pre>";
text += "\n<br/><br/>"+footer;
To structure and format the text, you have the basic options that HTML offers, such as line breaks, inserting mailto addresses, inserting images, etc. The response text defined in this way is stored in a separate variable "text", which we will need in the rest of the script.
The script line of the above block
addresses the signature text of the mailbox. In our example, this looks like this:
<table border="0" style="border: none;">
<tr>
<td style="border: none;">
<strong>Muster und Sohn AG</strong><br/>
Max Muster & Siegfried Sohn<br/>
Muster Str. 42<br/>
12345 Musterstadt<br/><br/>
Tel. 12345 678999<br/>
</td>
<td style="border: none; vertical-align: top; padding-left: 20px;">
</td>
</table>
Here, too, you have all the options of HTML at your disposal to structure and format the text.
Now we have defined the content and structure of the reply email and only need to send it automatically. We do this using the method of the helper object "helper.sendmail". However, we first evaluate whether the original sender has set a reply-to address and send the reply to this. The script snippet for this, as well as for the regular sending of the reply email if no reply-to address is set, looks like this:
if(emailreplyto!=null)
{
helper.sendmail(task.source.sourcemailbox.emailAddress, "Re: "+message.getSubject()+" (ID: "+id+")", text, emailreplyto, null, null, null, true)
}
// Ende Autoreply, wenn Reply-to gefüllt ist.
else {
helper.sendmail(task.source.sourcemailbox.emailAddress, "Re: "+message.getSubject()+" (ID: "+id+")", text, toEmail, null, null, null, true);
}
The overall script for the "Receive Action" of your mailbox now needs to be adapted to your needs. If you need support with this, please contact us at support@bergener-bluma.de
var toEmail = message.getFrom()[0].getAddress();
var css=helper.getServerPropertyByName('emailCss');
var footer = task.source.sourcemailbox.footer;
var emailreplyto = task.getProperty("EMAILREPLYTO");
var text = "<html><head></head><body><p>Sehr geehrte Kundin, sehr geehrter Kunde,<br/><br/>\n";
text += "hiermit bestätigen wir den Erhalt Ihrer Nachricht.<br/><br/>";
text += "Wir werden Ihr Anliegen sorgfältig prüfen und uns schnellstmöglich bei Ihnen melden.<br/>\n";
text += "Bei Rückfragen geben Sie bitte die Bearbeitungsnummer "+id+" im Betreff an.<br/><br/>\n";
text += "Mit freundlichen Grüßen<br/>\n";
text += "Muster und Sohn AG<br/></p>\n";
text += "<hr/><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 += "Muster und Sohn AG<br/></p><br/>\n";
text += "</p><br/>\n";
text += "Betreff Ihrer Nachricht / Subject of your request:<br/><pre>"+ message.getSubject()+"</pre>";
text += "\n<br/><br/>"+footer;
// Start Autoreply, wenn Reply-to gefüllt ist.
if(emailreplyto!=null)
{
helper.sendmail(task.source.sourcemailbox.emailAddress, "Re: "+message.getSubject()+" (ID: "+id+")", text, emailreplyto, null, null, null, true)
}
// Ende Autoreply, wenn Reply-to gefüllt ist.
else {
helper.sendmail(task.source.sourcemailbox.emailAddress, "Re: "+message.getSubject()+" (ID: "+id+")", text, toEmail, null, null, null, true);
}