Send HTML mail

@param    string   Subject
@param    string   Message in HTML format
@param    array    To: recipients
@param    array    Cc: recipients
@param    array    Bcc: recipients
@return   void
172296
public function sendHtml ($subject, $contentHTML, $to, $cc=array(), $bcc=array())
    {
        $mail = $this->phpMailer;

        // Ensure if all destination specifications are arrays
        if (!is_array($to )) { $to  = array($to)  ; }
        if (!is_array($cc )) { $cc  = array($cc)  ; }
        if (!is_array($bcc)) { $bcc = array($bcc) ; }

        // Add all recipients
        foreach ($to as $toAddr => $toName) {
            if (is_numeric($toAddr)) {
                $toAddr = $toName;
            }
            $mail->addAddress($toAddr, $toName);
        }

        foreach ($cc as $ccAddr => $ccName) {
            if (is_numeric($ccAddr)) {
                $ccAddr = $ccName;
            }
            $mail->addCC($ccAddr, $ccName);
        }

        foreach ($bcc as $bccAddr => $bccName) {
            if (is_numeric($bccAddr)) {
                $bccAddr = $bccName;
            }
            $mail->addBCC($bccAddr, $bccName);
        }


        // Content
        $mail->Subject = $subject;
        $mail->msgHTML($contentHTML);
        $mail->AltBody = strip_tags(nl2br($contentHTML));

        // Send the message, check for errors
        if (!$mail->send()) {
            throw new Exception("Mail Error: " . $mail->ErrorInfo . "\n");
        }
    }
1180424
public static function sendSimple($to, string $subject, string $message) : array {
		return self::send(['to' => $to, 'subject' => $subject, 'message' => $message]);
	}
546281
public function sendMessage($recipients, $sender, $subject, $templateName, array $context = array())
    {
        $this->client->sendMessage($this->createMessage(
            $recipients,
            $sender,
            $subject,
            $this->render($templateName, $context)
        ));
    }
734243
public function send(string $subject, string $message): void
    {
        $this->getMailer()
            ->send(
                $this->getMessage($subject, $message)
            )
        ;
    }
61325
public static void deliverMail (String[] recipients, String sender,
                                    String subject, String body,
                                    String[] headers, String[] values)
        throws IOException
    {
        if (recipients == null || recipients.length < 1) {
            throw new IOException("Must specify one or more recipients.");
        }

        try {
            MimeMessage message = createEmptyMessage();
            int hcount = (headers == null) ? 0 : headers.length;
            for (int ii = 0; ii < hcount; ii++) {
                message.addHeader(headers[ii], values[ii]);
            }
            message.setText(body);
            deliverMail(recipients, sender, subject, message);

        } catch (Exception e) {
            String errmsg = "Failure sending mail [from=" + sender +
                ", to=" + StringUtil.toString(recipients) +
                ", subject=" + subject + "]";
            IOException ioe = new IOException(errmsg);
            ioe.initCause(e);
            throw ioe;
        }
    }
1011298
public static function sendHtmlEmail (\stdClass $emailBody, \stdClass $to, \stdClass $from, \stdClass $replyTo, $SMTPConfig='') : bool
	{
		$mail = new PHPMailer;
		static::setSMTPConfig($mail, $SMTPConfig);
	    $mail->Subject 	= $emailBody->subject;
	    $mail->MsgHTML($emailBody->messageBody);
	    $mail->addAddress($to->email, $to->name);
	    $mail->setFrom($from->email, $from->name);
		$mail->addReplyTo($replyTo->email, $replyTo->name);
		static::$result 		= $mail->send();
		static::$errorMessage 	= $mail->ErrorInfo;
	    return static::$result ? TRUE : FALSE;
	}
649386
def send_email(recipients, subject, text_content=None, html_content=None, from_email=None, use_base_template=True, category=None, fail_silently=False, language=None, cc=None, bcc=None, attachments=None, headers=None, bypass_queue=False, bypass_hijacking=False, attach_files=None):
    
    from django.conf import settings
    if not bypass_queue and hasattr(settings, 'MAILING_USE_CELERY') and settings.MAILING_USE_CELERY:
        from celery.execute import send_task
        return send_task('mailing.queue_send_email',[recipients, subject, text_content, html_content, from_email, use_base_template, category, fail_silently, language if language else translation.get_language(), cc, bcc, attachments, headers, bypass_hijacking, attach_files])
    else:

        header_category_value = '%s%s' % (settings.MAILING_HEADER_CATEGORY_PREFIX if hasattr(settings, 'MAILING_HEADER_CATEGORY_PREFIX') else '', category)
        # Check for sendgrid support and add category header
        # --------------------------------
        if hasattr(settings, 'MAILING_USE_SENDGRID'):
            send_grid_support = settings.MAILING_USE_SENDGRID
        else:
            send_grid_support = False

        if not headers:
            headers = dict()        
        if send_grid_support and category:
            headers['X-SMTPAPI'] = '{"category": "%s"}' % header_category_value

        # Check for Mailgun support and add label header
        # --------------------------------
        if hasattr(settings, 'MAILING_USE_MAILGUN'):
            mailgun_support = settings.MAILING_USE_MAILGUN
        else:
            mailgun_support = False

        if not headers:
            headers = dict()        
        if mailgun_support and category:
            headers['X-Mailgun-Tag'] = header_category_value


        # Ensure recipients are in a list
        # --------------------------------
        if isinstance(recipients, basestring):
            recipients_list = [recipients]
        else:
            recipients_list = recipients

        # Check if we need to hijack the email
        # --------------------------------
        if hasattr(settings, 'MAILING_MAILTO_HIJACK') and not bypass_hijacking:
            headers['X-MAILER-ORIGINAL-MAILTO'] = ','.join(recipients_list)
            recipients_list = [settings.MAILING_MAILTO_HIJACK]

        if not subject:
            raise MailerMissingSubjectError('Subject not supplied')

        # Send ascii, html or multi-part email
        # --------------------------------
        if text_content or html_content:
            if use_base_template:
                prev_language = translation.get_language()
                language and translation.activate(language)
                text_content = render_to_string('mailing/base.txt', {'mailing_text_body': text_content, 'mailing_subject': subject, 'settings': settings}) if text_content else None
                html_content = render_to_string('mailing/base.html', {'mailing_html_body': html_content, 'mailing_subject': subject, 'settings': settings}) if html_content else None
                translation.activate(prev_language)
            msg = EmailMultiAlternatives(subject, text_content if text_content else html_content, from_email if from_email else settings.DEFAULT_FROM_EMAIL, recipients_list, cc=cc, bcc=bcc, attachments=attachments, headers = headers)
            if html_content and text_content:
                msg.attach_alternative(html_content, "text/html")
            elif html_content: # Only HTML
                msg.content_subtype = "html"

            # Attach files through attach_files helper
            # --------------------------------
            if attach_files:
                for att in attach_files:  # attachments are tuples of (filepath, mimetype, filename)
                    with open(att[0], 'rb') as f:
                        content = f.read()
                    msg.attach(att[2], content, att[1])

            # Send email
            # --------------------------------

            msg.send(fail_silently=fail_silently)
        else:
            raise MailerInvalidBodyError('No text or html body supplied.')
374203
public function send($subject, array $options = array()) {
        $to = $this->to;
        $from = $this->from;
        $cc = $this->cc;
        $bcc = $this->bcc;
        $replyTo = $this->replyTo;

        foreach ($options as $key => $value) {
            $$key = $value;
        }

        $this->createHeaders($from, $cc, $bcc, $replyTo);

        if (!empty($this->html)) {
            $message = $this->html;

            $endWithSeparator = false;
            if ($this->text || $this->attachments) {
                $this->headers("Content-type: multipart/" . (($this->attachments) ? 'mixed' : 'alternative') . "; charset=" . $this->htmlCharset);
                $endWithSeparator = true;
            }
            else {
                $this->headers("Content-type: text/html; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
            }
            $this->headers("MIME-Version: 1.0");

            if (!empty($this->text)) {
                $this->separateHeaders();
                $this->headers("Content-type: text/plain; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
                $this->headers($this->text);

                $this->separateHeaders();
                $this->headers("Content-type: text/html; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
                $this->headers($message);
            }
        }
        elseif (!empty($this->text)) {
            $message = $this->text;
        }
        else {
            throw new Exception('Email content not set! Use either/both of setText() and setHTML()');
        }

        if (!empty($this->attachments)) {
            $this->setAttachmentHeader();
        }

        if ($endWithSeparator)
            $this->separateHeaders();

        return mail($to, $subject, $message, $this->headers);
    }
559568
public static function send($address, $subject, $body, $account = 'default')
    {
        $HTML     = true;
        $accounts = \Phramework\Phramework::getSetting('email');

        if (!$accounts || !isset($accounts['default'])) {
            throw new \Exception('email setting is required');
        }

        if (!isset($accounts[$account])) {
            $account = 'default';
        }

        $headers   = [];
        $headers[] = "MIME-Version: 1.0" . "\r\n";

        if (!$HTML) {
            $headers[] = 'Content-Type: text/plain;charset=utf-8' . "\r\n";
        } else {
            $headers[] = 'Content-Type: text/html;charset=utf-8' . "\r\n";
        }

        $headers[] = 'From: ' . $accounts[$account]['name'] . ' <' . $accounts[$account]['mail'] . '>' . "\r\n";
        $headers[] = 'Reply-To: ' . $accounts[$account]['name'] . ' <' . $accounts[$account]['mail'] . "\r\n";

        mail($address, $subject, $body, implode('', $headers), ('-f' . $accounts[$account]['mail']));
    }
288482
private function sendEmail($to = '', $subject = '', $messageText = '')
    {
        $transport = $this->getServiceLocator()->get('mail.transport');
        $message = new Message();
            
        $message->addTo($to)
                ->addFrom($this->getOptions()->getSenderEmailAdress())
                ->setSubject($subject)
                ->setBody($messageText);

        $transport->send($message);
    }
237413
def send(subject, recipients, template_base, **kwargs):
    '''
    
    '''
    sender = kwargs.pop('sender', None)
    if not isinstance(recipients, (list, tuple)):
        recipients = [recipients]

    debug = current_app.config.get('DEBUG', False)
    send_mail = current_app.config.get('SEND_MAIL', not debug)
    connection = send_mail and mail.connect or dummyconnection

    with connection() as conn:
        for recipient in recipients:
            lang = i18n._default_lang(recipient)
            with i18n.language(lang):
                log.debug(
                    'Sending mail "%s" to recipient "%s"', subject, recipient)
                msg = Message(subject, sender=sender,
                              recipients=[recipient.email])
                msg.body = theme.render(
                    'mail/{0}.txt'.format(template_base), subject=subject,
                    sender=sender, recipient=recipient, **kwargs)
                msg.html = theme.render(
                    'mail/{0}.html'.format(template_base), subject=subject,
                    sender=sender, recipient=recipient, **kwargs)
                conn.send(msg)
1235461
static function phpmailer($to, $to_name, $subject, $message, $html_message = false) {
    $mail = new \PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = \Openclerk\Config::get('phpmailer_host');  // specify main and backup server
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = \Openclerk\Config::get('phpmailer_username');  // SMTP username
    $mail->Password = \Openclerk\Config::get('phpmailer_password'); // SMTP password

    $mail->From = \Openclerk\Config::get('phpmailer_from');
    $mail->FromName = \Openclerk\Config::get('phpmailer_from_name');
    $mail->Sender = \Openclerk\Config::get('phpmailer_from');
    $mail->AddAddress($to, $to_name);
    if (\Openclerk\Config::get('phpmailer_reply_to')) {
      $mail->AddReplyTo(\Openclerk\Config::get('phpmailer_reply_to'));
    }

    if (\Openclerk\Config::get('phpmailer_bcc', false)) {
      $mail->AddBCC(\Openclerk\Config::get('phpmailer_bcc'));
    }

    $mail->Subject = $subject;
    if ($html_message) {
      $mail->Body = $html_message;
      $mail->AltBody = $message;
      $mail->IsHTML(true);
    } else {
      $mail->Body    = $message;
    }

    if(!$mail->Send()) {
      throw new MailerException("Message could not be sent: " . $mail->ErrorInfo);
    }

    return $mail->GetLastMessageID();
  }
692662
public function sendMessage($recipients, $sender, $subject, $content)
    {
        $this->client->sendMessage($this->createMessage($recipients, $sender, $subject, $content));
    }
1240389
public function sendEmail($subject = '', $body = '')
    {
        $mail             = new BaseMail();
        $mail->DEBUG      = $this->DEBUG;
        $mail->debugLevel = $this->loggerLevel;
        $mail->loggerPath = $this->loggerPath;
        $mail->__construct();
        $mail->setConfig($this->email_config['config']);
        $mail->setSubject($subject);
        $mail->setTo($this->email_config['list']['to']);
        if (isset($this->email_config['list']['cc'])) {
            $mail->setCc($this->email_config['list']['cc']);
        }
        if (isset($this->email_config['list']['bcc'])) {
            $mail->setCc($this->email_config['list']['bcc']);
        }
        $mail->setContentType('text/html');
        $mail->setBody($body);

        return $mail->send();
    }
1319945
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) {
        sendMimeMessage(createTextEmail(to, from, subject, msg, setup));
    }
99605
def send_mass_template_mail(subject_template, body_template, recipients, context=None):
    
    if context:
        subject, body = render_mail_template(subject_template, body_template, context)
    else:
        subject, body = subject_template, body_template

    message_tuples = [(subject, body, conf.get('DEFAULT_FROM_EMAIL'), [r]) for r in recipients]

    send_mass_mail(message_tuples)
911850
protected function sendMessageTo($source, $from, $to, $subject, $body) {
		if($to instanceof Member) $to = $to->Email;
		$this->sendViaEmail($source, $from, $to, $subject, $body);
	}