$auth_user, 'password' => $auth_password)); $msg = new EmailMessage($subject, $message, $from_email, $recipient_list, null, null, $connection); return $msg->send(); } /** * Given a datatuple of (subject, message, from_email, recipient_list), sends * each message to each recipient list. Returns the number of emails sent. * * If from_email is None, the DEFAULT_FROM_EMAIL setting is used. * If auth_user and auth_password are set, they're used to log in. * If auth_user is None, the EMAIL_HOST_USER setting is used. * If auth_password is None, the EMAIL_HOST_PASSWORD setting is used. */ public static function send_mass_mail(array $data, $fail_silently=false, $connection=null, $auth_user=null, $auth_password=null) { if (null === $connection) $connection = self::get_connection($fail_silently, null, array( 'username' => $auth_user, 'password' => $auth_password)); $messages = array_map(function($a) { return new EmailMessage($a[0], $a[1], $a[2], $a[3]); }, $data); return $connection->sendMessages($messages); } /** * Sends a message to the admins, as defined by the ADMINS setting. */ public static function mail_admins($subject, $message, $fail_silently=false, $connection=null, $html_message=null) { return self::mail_staff(array_keys(settings::get('ADMINS')), $subject, $message, $fail_silently, $connection, $html_message); } /** * Sends a message to the managers, as defined by the MANAGERS setting. */ public static function mail_managers($subject, $message, $fail_silently=false, $connection=null, $html_message=null) { return self::mail_staff(array_keys(settings::get('MANAGERS')), $subject, $message, $fail_silently, $connection, $html_message); } /* internal helpers */ static function mail_staff(array $to, $subject, $message, $fail_silently=false, $connection=null, $html_message=null) { if (!$to) return; $mail = new EmailMultiAlternatives( settings::get('EMAIL_SUBJECT_PREFIX') . $subject, $message, settings::get('SERVER_EMAIL'), $to, null, null, $connection); if ($html_message) $mail->attachAlternative($html_message, 'text/html'); $mail->send($fail_silently); } }