Please rate how useful you found this document: 
Average: 2.5 (4 votes)

Overview

By default all emails are sent out by the email server and user account which is configured under ADMIN > Settings > Email. In some processes, however, it may be appropriate to send emails from a different email server and/or user account. In version 2.8.0 and later, the config parameter has been added to the PMFSendMessage() function, to allow emails to be sent out with a different email server and/or user account.

Sending emails from different servers and user accounts

To create a trigger which sends out an email from a custom email server and/or user account, go to DESIGNER and open a process for editing. Then, go to the Triggers tab and click on New. Then select ProcessMaker Functions and click on the PMFSendMessage() in the list:

See the documentation for this function. The parameter to configure an alternative email server is the last parameter for the function.

The function definition for PMFSendMessage():

int PMFSendMessage(string caseId, string from, string to, string cc, string bcc,
    string subject, string template, array aFields=array(), array aAttachments=array(),
    boolean showMessage=true, int delIndex=0, array config=array())

To use an alternative email server and/or user account, the config parameter of PMFSendMessage() should be set to an associative array with the following values as the keys:

  • MESS_ENGINE: Select the email engine which will be used to send out emails. Possible values include:
    • "PHPMAILER": This option sends email using the PHPMailer program, which is recommended if using an external email service (such as Yahoo!, gmail, hotmail, etc.) or if the server running ProcessMaker is not configured to use a Mail Transfer Agent (such as SendMail, Postfix, exim, etc.).
    • "MAIL": This option uses PHP's mail() function to send the email, which means that the server running ProcessMaker should have a Mail Transfer Agent (such as SendMail, Postfix, Exim, etc.) and PHP should be configured to use it. If this option is used, then the MESS_SERVER, MESS_PORT and SMTPSecure parameters are ignored.
  • MESS_SERVER: The IP address or domain name for the email server. For example, "smtp.live.com" or "smtp.example.com".
  • MESS_PORT: The port number used by the email server. Generally port 25 is used, or alternatively port 587. If connecting to the email server with a SSL or TLS connection, generally port 465 is used.
  • MESS_ACCOUNT: The name which will be included in the From field of the message. It can be an email address, such as "johndoe@example.com", or a name, such as "John Doe" or "Acme Inc.". This value depends upon the email provider. For example, the gmail email server always uses an email address in this field. If this field is an email address, the MESS_FROM_MAIL parameter is ignored, but if it is a name, MESS_FROM_MAIL should be set to a valid email account.
  • MESS_FROM_MAIL: If MESS_ACCOUNT is set to a name, set this to the email address from which the notification will be send, such as: "johndoe@example.com"
  • MESS_RAUTH: Set to 1 if the server requires authentication, meaning that a password is required; otherwise, set it to 0.
  • MESS_PASSWORD: The password for the user account.
  • SMTPSecure: Select whether the email requires a secure connection:

Emailing members of a Group

In this example, the members of a group named "Employees" will receive emails from a gmail account, which is specified in the associative array $serverConfig which is passed to the config parameter of PMFSendMessage():

$groupName = 'Employees';  
$query = "SELECT DISTINCT GU.USR_UID FROM CONTENT AS C, GROUP_USER AS GU WHERE " .
   "C.CON_CATEGORY='GRP_TITLE' AND C.CON_VALUE='$groupName' AND C.CON_ID=GU.GRP_UID";
$result = executeQuery($query);
if (!is_array($result) or count($result) < 1) {
   $g = new G();
   $g->SendMessageText("Unable to find any users in group '$groupName'.", "WARNING");
}
else {
   $to = '';
   foreach ($result as $record) {
      $aInfo = userInfo($record['USR_UID']);
      if (empty($to))
         $to = $aInfo['mail'];
      else
         $to .= ', ' . $aInfo['mail'];
   }
   $serverConfig = array("MESS_ENGINE"=>"PHPMAILER", "MESS_SERVER"=>"smtp.gmail.com", "MESS_PORT"=>465,
      "MESS_ACCOUNT"=>"manager@company.com","MESS_FROM_MAIL"=>"", "MESS_PASSWORD"=>"xxxxxx",
      "SMTPSecure"=>"tls", "MESS_RAUTH" =>1);
   PMFSendMessage(@@APPLICATION,'manager@company.com', $to, '', '', 'Expenses for Project',
      'projectExpenses.html', array(), array(), true, 0, $serverConfig);
}