Versions Compared

Key

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

...

Table plus
applyColStyleToCelltrue
columnTypess,s,s,s
heading0
multiplefalse
enableSortingfalse

Parameter name

Type

Required

Description

from

String

No

From address

to

string []

Yes

Recipient list

cc

string []

No

CC'ed recipient list

subject

String

Yes

Subject

body_or_template

String

Yes

Message body, either direct or a template

language

String

No

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

issue_key

String

No

Issue to extract attachments from

regex_array

String []

No

Name patterns to match the attachments from the issue

wildcard_path_array

String []

No

Absolute paths containing wildcards for attaching files from disk

Return Type

/wiki/spaces/AA/pages/351830229#1

Examples

Example 1

Code Block
languagejs
sendEmail("projectmanager", "teamleader1", "Transition executed", currentUser() + " has executed a transition");
// here we have to, cc, subject and body.
// The from and language parameters were omitted.

...

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

Code Block
languagejs
string [] to = {"testJiraUser1", "testEmail@cprimetestEmail@appfire.com", "testJiraUser2"};
string [] cc = {"testEmail2@cprimetestEmail2@appfire.com"};
sendEmail("testFrom@cprimetestFrom@appfire.com", to, cc, "testSubject.tpl", "testBody.tpl");

Result: One email in French will be sent to testJiraUser1, one email in German for testJiraUser2 and one email in the sender defined language for testEmail@cprimetestEmail@appfire.com(as to) and testEmail2@cprimetestEmail2@appfire.com(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 user having the defined language French and testJiraUser2 is a Jira user having the defined language German.

Code Block
languagejs
string [] to = {"testJiraUser1", "testEmail@cprimetestEmail@appfire.com", "testJiraUser2"};
string [] cc = {"testEmail2@cprimetestEmail2@appfire.com"};
sendEmail("testFrom@cprimetestFrom@appfire.com", to, cc, "testSubject.tpl", "testBody.tpl", "en_US");

...

This example will demonstrate the ability to attach files (to the email) selected from the attachments of the issue using regex patterns.
We will assume that the issue has three attachments: attachment1.txt, attachment2.txt and attachment3.txt (note that this last one does not have a dot to separate the extension).
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
languagejs
sendEmail("santa@cprimesanta@appfire.com", {"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.

sendEmail("santa@cprimesanta@appfire.com", {"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 attachment3.txt.

sendEmail("santa@cprimesanta@appfire.com", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", "en_US", key, {"attachment1\.txt", "attachment3atxt"});
//This will match attachment1.txt and attachment3.txt.

...

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
languagejs
sendEmail("santa@cprimesanta@appfire.com", {"jira-users"}, {}, "santa_subject.tpl", "santa_letter.tpl", {"C:/gifts/jira-users*.gift"});

...

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

Code Block
languagejs
JEmailMessage email;
email.to = {"testJiraUser1", "testEmail@cprimetestEmail@appfire.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
languagejs
JEmailMessage email;
email.to = {"testJiraUser1", "testEmail@cprimetestEmail@appfire.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);

See also

...