function email_notify($check,$check_result,$subscription) { global $status_array; $user = new User($subscription->getUserId()); echo 'email plugin!'; $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP('smtp.gmail.com', 465, TRUE, 5); $smtp->authenticate('*****@*****.**', 'example'); $email->addRecipient($user->getEmail(), $user->getUsername()); // Set who the email is from $email->setFromEmail('*****@*****.**','Tattle'); // Set the subject include UTF-8 curly quotes $email->setSubject('Tattle : Alert for ' . $check->prepareName()); // Set the body to include a string containing UTF-8 $state = $status_array[$check_result->getStatus()]; $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . $fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>"); $email->setBody(" $state Alert for {$check->prepareName()} The check returned {$check_result->prepareValue()} Warning Threshold is : ". $check->getWarn() . " Error Threshold is : ". $check->getError() . " "); try { $message_id = $email->send($smtp); } catch ( fConnectivityException $e) { fCore::debug("email send failed",FALSE); } }
function email_plugin_notify($check,$check_result,$subscription,$alt_email=false) { global $status_array; $user = new User($subscription->getUserId()); $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), TRUE, 5); $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass')); if ($alt_email) { $email_address = usr_var('alt_email',$user->getUserId()); } else { $email_address = $user->getEmail(); } $email->addRecipient($email_address, $user->getUsername()); // Set who the email is from $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display')); // Set the subject include UTF-8 curly quotes $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject'))); // Set the body to include a string containing UTF-8 $state = $status_array[$check_result->getStatus()]; $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>"); $email->setBody(" $state Alert for {$check->prepareName()} The check returned {$check_result->prepareValue()} Warning Threshold is : ". $check->getWarn() . " Error Threshold is : ". $check->getError() . " "); try { $message_id = $email->send($smtp); } catch ( fConnectivityException $e) { fCore::debug("email send failed",FALSE); } }
function notify_multiple_users($user_from, $recipients, $subject, $body) { $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), sys_var('require_ssl') === 'true' ? TRUE : FALSE, 5); if (sys_var('require_auth') === 'true') { $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass')); } // Add the recipients foreach ($recipients as $rec) { $email->addRecipient($rec['mail'], $rec['name']); } // Set who the email is from $email->setFromEmail($user_from->getEmail(), $user_from->getUsername()); // Set the subject $email->setSubject($subject); // Set the body $email->setHTMLBody($body); $email->setBody($body); try { $message_id = $email->send($smtp); } catch (fConnectivityException $e) { fCore::debug($e, FALSE); fCore::debug("email send failed", FALSE); $e->printMessage(); $e->printTrace(); } }
/** * @dataProvider serverProvider */ public function testSendMultipleToCcBcc($server, $port, $secure, $username, $password) { $token = $this->generateSubjectToken(); $smtp = new fSMTP($server, $port, $secure, 10); if ($username) { $smtp->authenticate($username, $password); } $email = new fEmail(); $email->setFromEmail($username ? $username : '******'); $email->addRecipient(EMAIL_ADDRESS, 'Test User'); $email->addRecipient(str_replace('@', '_2@', EMAIL_ADDRESS), 'Test User 2'); $email->addCCRecipient(str_replace('@', '_3@', EMAIL_ADDRESS), 'Test User 3'); $email->addBCCRecipient(str_replace('@', '_4@', EMAIL_ADDRESS), 'Test User 4'); $email->setSubject($token . ': Testing Multiple Recipients'); $email->setBody('This is a test of sending multiple recipients'); $message_id = $email->send($smtp); $message = $this->findMessage($token, EMAIL_USER); $this->assertEquals($message_id, $message['headers']['message-id']); $this->assertEquals($username ? $username : '******', $message['headers']['from']['mailbox'] . '@' . $message['headers']['from']['host']); $this->assertEquals($token . ': Testing Multiple Recipients', $message['headers']['subject']); $this->assertEquals('This is a test of sending multiple recipients', trim($message['text'])); $message = $this->findMessage($token, str_replace('tests', 'tests_2', EMAIL_USER)); $this->assertEquals(array('personal' => 'Test User', 'mailbox' => 'tests', 'host' => 'flourishlib.com'), $message['headers']['to'][0]); $message = $this->findMessage($token, str_replace('tests', 'tests_3', EMAIL_USER)); $this->assertEquals(array('personal' => 'Test User 3', 'mailbox' => 'tests_3', 'host' => 'flourishlib.com'), $message['headers']['cc'][0]); $message = $this->findMessage($token, str_replace('tests', 'tests_4', EMAIL_USER)); $this->assertEquals(FALSE, isset($message['headers']['bcc'])); $smtp->close(); }
/** * @dataProvider serverProvider */ public function testSendMultipleToCcBcc($server, $port, $secure, $username, $password) { $token = $this->generateSubjectToken(); $smtp = new fSMTP($server, $port, $secure, 5); if ($username) { $smtp->authenticate($username, $password); } $email = new fEmail(); $email->setFromEmail($username ? $username : '******'); $email->addRecipient(EMAIL_ADDRESS, 'Test User'); $email->addRecipient(str_replace('@', '_2@', EMAIL_ADDRESS), 'Test User 2'); $email->addCCRecipient(str_replace('@', '_3@', EMAIL_ADDRESS), 'Test User 3'); $email->addBCCRecipient(str_replace('@', '_4@', EMAIL_ADDRESS), 'Test User 4'); $email->setSubject($token . ': Testing Multiple Recipients'); $email->setBody('This is a test of sending multiple recipients'); $message_id = $email->send($smtp); $message = $this->findMessage($token, EMAIL_USER); $this->assertEquals($message_id, $message['headers']['Message-ID']); $this->assertEquals($username ? $username : '******', $message['headers']['From']); $this->assertEquals($token . ': Testing Multiple Recipients', $message['headers']['Subject']); $this->assertEquals('This is a test of sending multiple recipients', trim($message['plain'])); $message = $this->findMessage($token, str_replace('tests', 'tests_2', EMAIL_USER)); // It seems the windows imap extension doesn't support the personal part of an email address $is_windows = stripos(php_uname('a'), 'windows') !== FALSE; $this->assertEquals($is_windows ? '*****@*****.**' : '"Test User" <*****@*****.**>', $message['headers']['To']); $message = $this->findMessage($token, str_replace('tests', 'tests_3', EMAIL_USER)); $this->assertEquals($is_windows ? '*****@*****.**' : '"Test User 3" <*****@*****.**>', $message['headers']['Cc']); $message = $this->findMessage($token, str_replace('tests', 'tests_4', EMAIL_USER)); $this->assertEquals(FALSE, isset($message['headers']['Bcc'])); $smtp->close(); }