/** * Send the notification. * * @return EmailResponse $return Response object */ public function push() { $this->mail->set_from($this->source); $this->mail->add_to($this->endpoint); $payload_array = json_decode($this->payload, TRUE); $this->mail->set_subject($payload_array['subject']); $this->mail->set_message($payload_array['body']); $response = $this->mail->send(); $res = new EmailResponse($response, $this->logger, $this->endpoint); $this->endpoint = ''; $this->payload = ''; return $res; }
function test_accessor_subject() { $msg = new Mail(); $subject = 'subject'; $msg->set_subject($subject); self::assertEquals($subject, $msg->get_subject()); }
public function testBasicMailConversion() { $mail = new Mail(); $mail->add_recipient('*****@*****.**', 'Toto'); $mail->set_sender('*****@*****.**', 'Tata'); $mail->set_content('hello world'); $mail->set_subject('hello'); $converter = new MailToPHPMailerConverter(); $phpmailer = $converter->convert($mail); self::assertEquals('hello', $phpmailer->Subject); self::assertEquals('hello world', $phpmailer->Body); }
public function send_from_properties($mail_to, $mail_subject, $mail_content, $mail_from = '', $sender_name = Mail::SENDER_ADMIN) { // Initialization of the mail properties $mail = new Mail(); $mail->add_recipient($mail_to); if ($mail_from == '') { $mail_from = MailServiceConfig::load()->get_default_mail_sender(); } $mail->set_sender($mail_from, $sender_name); $mail->set_subject($mail_subject); $mail->set_content($mail_content); // Let's send the mail return $this->try_to_send($mail); }
public function send_mail($subscribers, $sender, $subject, $contents) { $contents = $this->parse_contents($contents) . $this->add_unsubscribe_link(); foreach ($subscribers as $values) { $mail_subscriber = !empty($values['mail']) ? $values['mail'] : NewsletterDAO::get_mail_for_member($values['user_id']); if (!empty($mail_subscriber)) { $mail = new Mail(); $mail->set_sender($sender); $mail->set_is_html(true); $mail->set_subject($subject); $mail->set_content($contents); $mail->add_recipient($mail_subscriber); //TODO gestion des erreurs AppContext::get_mail_service()->try_to_send($mail); } } }
private function send_mail() { $message = ''; $current_user = AppContext::get_current_user(); $fields = $this->config->get_fields(); $recipients_field_id = $this->config->get_field_id_by_name('f_recipients'); $recipients_field = new ContactField(); $recipients_field->set_properties($fields[$recipients_field_id]); $recipients = $recipients_field->get_possible_values(); $recipients['admins']['email'] = implode(';', MailServiceConfig::load()->get_administrators_mails()); $subject_field_id = $this->config->get_field_id_by_name('f_subject'); $subject_field = new ContactField(); $subject_field->set_properties($fields[$subject_field_id]); $subjects = $subject_field->get_possible_values(); if ($subject_field->get_field_type() == 'ContactShortTextField') { $subject = $this->form->get_value('f_subject'); } else { $subject = $this->form->get_value('f_subject')->get_raw_value(); } $display_message_title = false; if ($this->config->is_tracking_number_enabled()) { $now = new Date(); $tracking_number = $this->config->get_last_tracking_number(); $tracking_number++; $message .= $this->lang['contact.tracking_number'] . ' : ' . ($this->config->is_date_in_tracking_number_enabled() ? $now->get_year() . $now->get_month() . $now->get_day() . '-' : '') . $tracking_number . ' '; $this->config->set_last_tracking_number($tracking_number); ContactConfig::save(); $subject = '[' . $tracking_number . '] ' . $subject; $display_message_title = true; } foreach ($this->config->get_fields() as $id => $properties) { $field = new ContactField(); $field->set_properties($properties); if ($field->is_displayed() && $field->is_authorized() && $field->is_deletable()) { try { $value = ContactFieldsService::get_value($this->form, $field); $message .= $field->get_name() . ': ' . $value . ' '; } catch (Exception $e) { throw new Exception($e->getMessage()); } $display_message_title = true; } } if ($display_message_title) { $message .= $this->lang['contact.form.message'] . ': '; } $message .= $this->form->get_value('f_message'); $mail = new Mail(); $mail->set_sender(MailServiceConfig::load()->get_default_mail_sender(), $this->lang['module_title']); $mail->set_reply_to($this->form->get_value('f_sender_mail'), $current_user->get_level() == User::VISITOR_LEVEL ? $this->lang['module_title'] : $current_user->get_display_name()); $mail->set_subject($subject); $mail->set_content($message); if ($recipients_field->is_displayed()) { if (in_array($recipients_field->get_field_type(), array('ContactSimpleSelectField', 'ContactSimpleChoiceField'))) { $recipients_mails = explode(';', $recipients[$this->form->get_value('f_recipients')->get_raw_value()]['email']); } else { $selected_recipients = $this->form->get_value('f_recipients'); $recipients_mails = array(); foreach ($selected_recipients as $recipient) { $mails = explode(';', $recipients[$recipient->get_id()]['email']); foreach ($mails as $m) { $recipients_mails[] = $m; } } } foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } else { if ($subject_field->get_field_type() != 'ContactShortTextField') { $recipient = $subjects[$this->form->get_value('f_subject')->get_raw_value()]['recipient']; $recipients_mails = explode(';', $recipients[$recipient]['email']); foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } else { $recipients_mails = explode(';', $recipients['admins']['email']); foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } } $mail_service = AppContext::get_mail_service(); if ($this->config->is_sender_acknowledgment_enabled()) { $acknowledgment = new Mail(); $acknowledgment->set_sender(MailServiceConfig::load()->get_default_mail_sender(), Mail::SENDER_ADMIN); $acknowledgment->set_subject('[' . $this->lang['contact.acknowledgment_title'] . '] ' . $subject); $acknowledgment->set_content($this->lang['contact.acknowledgment'] . $message); $acknowledgment->add_recipient($this->form->get_value('f_sender_mail')); return $mail_service->try_to_send($mail) && $mail_service->try_to_send($acknowledgment); } return $mail_service->try_to_send($mail); }
private function send_mail() { if ($this->form->get_value('use_smtp')) { $configuration = new SMTPConfiguration(); $configuration->set_host($this->form->get_value('smtp_host')); $configuration->set_port($this->form->get_value('smtp_port')); $configuration->set_login($this->form->get_value('smtp_login')); $configuration->set_password($this->form->get_value('smtp_password')); $configuration->set_auth_mode($this->form->get_value('secure_protocol')->get_raw_value()); $mailer = new SMTPMailService($configuration); } else { $mailer = new DefaultMailService(); } $mail = new Mail(); $mail->add_recipient($this->form->get_value('recipient_mail'), $this->form->get_value('recipient_name')); $mail->set_sender($this->form->get_value('sender_mail'), $this->form->get_value('sender_name')); $mail->set_subject($this->form->get_value('mail_subject')); $mail->set_content($this->form->get_value('mail_content')); return $mailer->send($mail); }
/** * @see AuthInterface::forgot_password() * @param string $username * @param string $name * @return bool */ public function forgot_password($username, $mail) { if ($username and $mail) { $system_log = new SystemLog(null); if (User::exist_username($username)) { $user_id = User::get_user_id_by_username($username); $user = new User($user_id); if ($user->check_mail(strtolower($mail))) { if ($user->get_boolean_user_entry("user_inactive") == false) { $new_password = User::generate_password(); $mail = new Mail(); $mail->set_recipient($user_id); $mail->set_subject("Your New Open-LIMS Password"); $mail->set_text("Your new password: "******"must_change_password", true); // Password sended successfully $system_log->create($user_id, 1, 1, "Password Send", "Forgot Password", "auth.php", null, null); return true; } else { // Error via sending throw new AuthForgotPasswordSendFailedException("", 0); } } else { // Inactive User $system_log->create($user_id, 1, 1, "Inactive User", "Forgot Password", "auth.php", null, null); throw new AuthUserNotFoundException("", 0); } } else { // Wrong E-Mail $system_log->create($user_id, 1, 0, "Wrong E-Mail", "Forgot Password", "auth.php", null, null); throw new AuthUserNotFoundException("", 0); } } else { // User Not Found $system_log->create(null, 1, 0, "User \"" . $username . "\" Not Found", "Forgot Password", "auth.php", null, null); throw new AuthUserNotFoundException("", 0); } } else { throw new AuthUserNotFoundException("", 0); } }