Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Warning

Looking for the documentation on the newest versions of SIL Engine and the Simple Issue Language for Jira 8 for Server/Data Center? Click here !


Info
titleAvailability

This routine is available starting with katl-commons SIL Engine™ 1.0, changed in 1.1.14 for Jira 4.3.x / 4.4.x and 2.0.7 for Jira 5.x.

...

sendEmail([from], to, [cc], subject, body_or_template, [language])

Starting with katl-commons commons 2.0.7, the syntax is following:

sendEmail(from, to, cc, subject, body_or_template, language, issue_key, regex_array)

sendEmail(from, to, cc, subject, body_or_template, language, wildcard_path_array)

Or

sendEmail(JEmailMessage)

Description

Excerpt

Sends an email.

...

To pass the language specify the 'sender', 'to', 'cc', 'subject', 'body' and finally the 'language', as a string (for instance "en", "fr", "en_US", "ro", etc.and so on). However, this is relevant only if you use templates as they support localization.

...

If you don't specify the language parameter and you use templates, by default the messages are sent in the sender defined language. For the users that are Jira users ('to' or 'cc' are user names and not email addresses) the language defined in the user profile(for each user) is used for email sending. For the rest of the users the email is sent using the sender defined language.

Starting with version 4.0, the engine automatically detects HTML or plain text messages.

Parameters

Parameter name

Type

Required

Description

from

string

no

the from

From address

to

string []

yes

recipient

Recipient list

cc

string []

no

CC'ed recipient list

subject

string

yes

subject

Subject

body_or_template

string

yes

message

Message body, either direct or a template

language

string

no

the language

Language used to send the email(relevant only if you use templates)

issue_keystringno
the issue
Issue to extract attachments from
regex_arraystring []if issue_key is present
name
Name patterns to match the attachments from the issue
wildcard_path_arraystring []no
absolute
Absolute paths containing wildcards for attaching files from disk

Or

Parameter name

Type

Required

Description




JEmailMessage








JEmailMessage







yes







Predefined email message structure. The structure contains the following fields
Field NameField TypeRequiredDescription
tostring []yessee above
ccstring []nosee above
bccstring []nosee above
subjectstringyessee above
messagestringyessee above
fromstringnosee above
attachmentsJEmailAttachment []nosee above
plainTextbooleannoforces sending email in plain text format


Alias

For historical reasons, this routine may be named 'sendEmailFrom'.

Starting with version 4.0, 'sendHtmlEmail' was registered as an alias, too (there is no need for sendHtmlEmail anymore)

...

If SendEmailLanguage has the value receiver_language, testJiraUser1 is a JIRA Jira user having the defined language French and testJiraUser2 is a JIRA Jira user having the defined language German.

Code Block
string [] to = {"testJiraUser1", "testEmail@keplertestEmail@cprime.rocom", "testJiraUser2"};
string [] cc = {"testEmail2@keplertestEmail2@cprime.rocom"};
sendEmail("testFrom@keplertestFrom@cprime.rocom", to, cc, "testSubject.tpl", "testBody.tpl");

Result: It One email in French will be sent one email in French for to testJiraUser1, one email in German for testJiraUser2 and one email in the sender defined language for testEmail@keplertestEmail@cprime.rocom(as to) and testEmail2@keplertestEmail2@cprime.rocom(as cc).

Example 3

Is similar with example 2, but here the language parameter is used.

If SendEmailLanguage has the value receiver_language, testJiraUser1 is a JIRA Jira user having the defined language French and testJiraUser2 is a JIRA Jira user having the defined language German.

Code Block
string [] to = {"testJiraUser1", "testEmail@keplertestEmail@cprime.rocom", "testJiraUser2"};
string [] cc = {"testEmail2@keplertestEmail2@cprime.rocom"};
sendEmail("testFrom@keplertestFrom@cprime.rocom", to, cc, "testSubject.tpl", "testBody.tpl", "en_US");

...

Now let's see a few examples of regex patterns that will match some of the attachment. Note that we will use key to specify the current issue, but feel free to use any other issue key.

Code Block
sendEmail("santa@keplersanta@cprime.rocom", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", "en_US", key, {"attachment.*"}); 

This will match all of the attachments. Since we are using regex patterns, attachment.* will match anything that starts with attachment.

Code Block
sendEmail("santa@keplersanta@cprime.rocom", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", "en_US", key, {"attachment.\\.txt"}); 

This will match attachment1.txt and attachment2.txt. The first dot will match any character (the 1 and 2). Note that the second dot is escaped using double backslashes and will not match attachment3atxt.

Code Block
sendEmail("santa@keplersanta@cprime.rocom", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", "en_US", key, {"attachment1\\.txt", "attachment3atxt"}); 

...

You can also attach files directly from disk by specifying absolute paths. Note that you can also use * (anything) and ? (any single char) as wildcards.

Code Block
sendEmail("santa@keplersanta@cprime.rocom", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", {"C:/gifts/jira-users*.gift"}); 

Example 6 - JEmailMessage

You can also use the JEmailMessage structure type when sending an email. This option can make the code a little cleaner.

Code Block
JEmailMessage email;
email.to = {"testJiraUser1", "testEmail@cprime.com", "testJiraUser2"};
email.subject = "Email to Santa";
email.message = "Dear Santa, I want a train.";

sendEmail(email);

Here is the same example that includes adding attachments to the email. This requires the use of the JEmailAttachment structure type.

Code Block
JEmailMessage email;
email.to = {"testJiraUser1", "testEmail@cprime.com", "testJiraUser2"};
email.subject = "Email to Santa";
email.message = "Dear Santa, I want a train.";


for(string a in attach) {   
    JEmailAttachment att;
    att.name = a;
    att.file = getAttachmentPath(key, a);
    email.attachments += att;
}

sendEmail(email);

Notes

Note

If you would like to use templates for emails, see the Mail configuration page, as well as detailed explanations linked our template engine: SIL SIL™ Template language. Specifically, read Email templates page.

...

Filter by label (Content by label)
showLabelsfalse
showSpacefalse
cqllabel = "smtp_support"
labelssmtp_support