Global.sendMail (from, to, subject, body)
general mail-sending function

  • Parameter String:
    sending email address
  • Parameter Obj:
    String or Array of Strings containing recipient email addresses
  • Parameter String:
    subject line
  • Parameter String:
    Body to use in email
  • Returns
    Obj Message object
Sourcecode in Global/objectFunctions.js:
1:   function sendMail(from, to, subject, body) {
2:      if (!from || !to || !body)
3:         throw new MailException("mailMissingParameters");
4:      var mail = new Mail();
5:      mail.setFrom(from ? from : root.sys_email);
6:      if (to && to instanceof Array) {
7:         for (var i in to)
8:            mail.addBCC(to[i]);
9:      } else
10:        mail.addTo(to);
11:     mail.setSubject(subject);
12:     mail.setText(body);
13:     switch (mail.status) {
14:        case 10 :
15:           throw new MailException("mailSubjectMissing");
16:           break;
17:        case 11 :
18:           throw new MailException("mailTextMissing");
19:           break;
20:        case 12 :
21:           throw new MailException("mailPartMissing");
22:           break;
23:        case 20 :
24:           throw new MailException("mailToInvalid");
25:           break;
26:        case 21 :
27:           throw new MailException("mailCCInvalid");
28:           break;
29:        case 22 :
30:           throw new MailException("mailCCInvalid");
31:           break;
32:        case 30 :
33:           throw new MailException("mailSend");
34:           break;
35:     }
36:     // finally send the mail
37:     mail.queue();
38:     return new Message("mailSend");
39:  }