Construct the email message
@return boolean
975525
public function Build ()
    {

        // Create Boundaries

        $boundary		= '=====' . md5 (uniqid (time ()));

        // Reset headers

        $this->_headers	= array ();

        // Add MIME Headers

        $this->addHeader ('MIME-version: 1.0');
        $this->addHeader ('Content-Type: Multipart/alternative;' . $this->_nl . chr (9) . 'boundary="' . $boundary . '"');

        // Start Message

        $this->_message	= NULL;

        // If there is a template file

        if ($this->_tpl)
        {

            // Load it and add to html

            $this->addHTML (@file_get_contents ($this->_tpl));

        }

        // If HTML data

        if ($this->_htmlSet || $this->_plain)
        {

            // Construct the HTML and add it to the message

            $this->_message	.= $this->constructHTML ($boundary);

        }

        // If Body

        if ($this->_bodySet)
        {

            // Construct the body

            if (!$this->constructBody ())
            {

                // Add error and return FALSE

                new \Sonic\Message ('error', 'Cannot add message body!');
                return FALSE;

            }

        }

        // If Attachments

        if ($this->_attachmentsSet)
        {

            // Add them to the message

            foreach ($this->_attachments as $attachment)
            {
                $this->_message	.= $this->constructAttachment ($attachment, $boundary);
            }

        }

        // Finish Message

        $this->_message	.= '--' . $boundary . '--' . $this->_nl;

        // Return TRUE

        return TRUE;

    }
1050897
public function getEmailMultiLanguage()
    {
        if ($this->offsetExists('email') && isset($this->email['multiLanguage'])) {
            return (boolean) $this->email['multiLanguage'];
        } else {
            return true;
        }
    }
1263653
private function createEmail(): self
    {
        $aFields  = $this->getArguments();
        $aCreated = [];

        try {

            $aToCreate = [];
            $aEmails   = array_filter(
                array_map(function ($sEmail) {
                    return implode('/', array_map('ucfirst', explode('/', ucfirst(trim($sEmail)))));
                }, explode(',', $aFields['EMAIL_NAME']))
            );

            sort($aEmails);

            foreach ($aEmails as $sEmail) {

                $sEmail = ucwords($sEmail);
                $sEmail = str_replace(' ', '', $sEmail);

                $aEmailBits = explode('/', $sEmail);
                $aEmailBits = array_map('ucfirst', $aEmailBits);

                $sNamespace       = $this->generateNamespace($aEmailBits);
                $sClassName       = $this->generateClassName($aEmailBits);
                $sClassNameFull   = $sNamespace . '\\' . $sClassName;
                $sClassNameNormal = str_replace('AppFactory', '', str_replace('\\', '', $sClassNameFull));
                $sFilePath        = $this->generateFilePath($aEmailBits);
                $sEmailKey        = $this->generateEmailKey($aEmailBits);
                $sTemplateDir     = $this->generateTemplateDir($aEmailBits);
                $sTemplateHtml    = $this->generateTemplate('HTML', $aEmailBits);
                $sTemplateText    = $this->generateTemplate('TEXT', $aEmailBits);

                //  Test it does not already exist
                if (file_exists($sFilePath)) {
                    throw new ConsoleException(
                        'An email at "' . $sFilePath . '" already exists'
                    );
                }
                try {
                    $oTest = Factory::factory($sClassNameNormal, 'app');
                    throw new ConsoleException(
                        'An email by "' . $sClassNameNormal . '" is already defined'
                    );
                } catch (\Exception $e) {
                    //  No exception? No problem!
                }

                $aToCreate[] = [
                    'NAMESPACE'             => $sNamespace,
                    'CLASS_NAME'            => $sClassName,
                    'CLASS_NAME_FULL'       => $sClassNameFull,
                    'CLASS_NAME_NORMALISED' => $sClassNameNormal,
                    'FILE_PATH'             => $sFilePath,
                    'DIRECTORY'             => dirname($sFilePath) . DIRECTORY_SEPARATOR,
                    'EMAIL_KEY'             => $sEmailKey,
                    'TEMPLATE_DIR'          => $sTemplateDir,
                    'TEMPLATE_HTML'         => $sTemplateHtml,
                    'TEMPLATE_TEXT'         => $sTemplateText,
                ];
            }

            $this->oOutput->writeln('The following email(s) will be created:');
            foreach ($aToCreate as $aConfig) {
                $this->oOutput->writeln('');
                $this->oOutput->writeln('Class:       <info>' . $aConfig['CLASS_NAME_FULL'] . '</info>');
                $this->oOutput->writeln('Key:         <info>' . $aConfig['CLASS_NAME_NORMALISED'] . '</info>');
                $this->oOutput->writeln('Path:        <info>' . $aConfig['FILE_PATH'] . '</info>');
                $this->oOutput->writeln('View (HTML): <info>' . $aConfig['TEMPLATE_HTML'] . '</info>');
                $this->oOutput->writeln('View (TEXT): <info>' . $aConfig['TEMPLATE_TEXT'] . '</info>');
            }
            $this->oOutput->writeln('');

            if ($this->confirm('Continue?', true)) {

                //  Generate emails
                $aServiceDefinitions = [];
                foreach ($aToCreate as $aConfig) {
                    $this->oOutput->writeln('');
                    $this->oOutput->write('Creating email <comment>' . $aConfig['CLASS_NAME_FULL'] . '</comment>... ');
                    $this->createPath($aConfig['DIRECTORY']);
                    $this->createFile(
                        $aConfig['FILE_PATH'],
                        $this->getResource('template/email.php', $aConfig)
                    );
                    $aCreated[] = $aConfig['FILE_PATH'];
                    $this->oOutput->writeln('<info>done!</info>');

                    //  Generate templates
                    $this
                        ->createPath($aConfig['TEMPLATE_DIR'])
                        ->createFile($aConfig['TEMPLATE_HTML'])
                        ->createFile($aConfig['TEMPLATE_TEXT']);

                    //  Generate the service definition
                    $aDefinition           = [
                        str_repeat(' ', $this->iServicesIndent) . '\'' . $aConfig['CLASS_NAME_NORMALISED'] . '\' => function () {',
                        str_repeat(' ', $this->iServicesIndent) . '    return new ' . $aConfig['CLASS_NAME_FULL'] . '();',
                        str_repeat(' ', $this->iServicesIndent) . '},',
                    ];
                    $aServiceDefinitions[] = implode("\n", $aDefinition);

                    //  Add to the email config
                    $this->addEmailConfig($aConfig);
                }

                //  Add services to the app's services array
                $this->oOutput->writeln('');
                $this->oOutput->write('Adding email(s) to app services... ');
                $this->writeServiceFile($aServiceDefinitions);
                $this->oOutput->writeln('<info>done!</info>');
            }

        } catch (ConsoleException $e) {
            $this->oOutput->writeln('<error>failed!</error>');
            //  Clean up created services
            if (!empty($aCreated)) {
                $this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
                foreach ($aCreated as $sPath) {
                    @unlink($sPath);
                }
            }
            throw new ConsoleException($e->getMessage());
        }

        return $this;
    }
34269
public function _construct()
    {
        $this->_init(
            \Dotdigitalgroup\Email\Model\Review::class,
            \Dotdigitalgroup\Email\Model\ResourceModel\Review::class
        );
    }
1256950
public function getSentMIMEMessage()
    {
        return rtrim($this->MIMEHeader . $this->mailHeader, "\n\r") . static::$LE . static::$LE . $this->MIMEBody;
    }
1102524
public function generateBody()
    {
        $result = $this->addHeadersSection( $this->message ) . ezcMailTools::lineBreak();
        for ( $i = 0; $i < count( $this->recipients ); $i++ )
        {
            $result .= $this->addHeadersSection( $this->recipients[$i] ) . ezcMailTools::lineBreak();
        }
        return $result;
    }
271449
public function build()
    {
        $mainPart = false;

        // create the text part if there is one
        if ( $this->plainText != '' )
        {
            $mainPart = new ezcMailText( $this->plainText, $this->charset );
        }

        // create the HTML part if there is one
        $htmlPart = false;
        if ( $this->htmlText != '' )
        {
            $htmlPart = $this->generateHtmlPart();

            // create a MultiPartAlternative if a text part exists
            if ( $mainPart != false )
            {
                $mainPart = new ezcMailMultipartAlternative( $mainPart, $htmlPart );
            }
            else
            {
                $mainPart = $htmlPart;
            }
        }

        // build all attachments
        // special case, mail with no text and one attachment.
        // A fix for issue #14220 was added by wrapping the attachment in
        // an ezcMailMultipartMixed part
        if ( $mainPart == false && count( $this->attachments ) == 1 )
        {
            if ( isset( $this->attachments[0][1] ) )
            {
                if ( is_resource( $this->attachments[0][1] ) )
                {
                    $mainPart = new ezcMailMultipartMixed( new ezcMailStreamFile( $this->attachments[0][0], $this->attachments[0][1], $this->attachments[0][2], $this->attachments[0][3] ) );
                }
                else
                {
                    $mainPart = new ezcMailMultipartMixed( new ezcMailVirtualFile( $this->attachments[0][0], $this->attachments[0][1], $this->attachments[0][2], $this->attachments[0][3] ) );
                }
            }
            else
            {
                $mainPart = new ezcMailMultipartMixed( new ezcMailFile( $this->attachments[0][0], $this->attachments[0][2], $this->attachments[0][3] ) );
            }
            $mainPart->contentDisposition = $this->attachments[0][4];
        }
        else if ( count( $this->attachments ) > 0 )
        {
            $mainPart = ( $mainPart == false )
                ? new ezcMailMultipartMixed()
                : new ezcMailMultipartMixed( $mainPart );

            // add the attachments to the mixed part
            foreach ( $this->attachments as $attachment )
            {
                if ( isset( $attachment[1] ) )
                {
                    if ( is_resource( $attachment[1] ) )
                    {
                        $part = new ezcMailStreamFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] );
                    }
                    else
                    {
                        $part = new ezcMailVirtualFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] );
                    }
                }
                else
                {
                    $part = new ezcMailFile( $attachment[0], $attachment[2], $attachment[3] );
                }
                $part->contentDisposition = $attachment[4];
                $mainPart->appendPart( $part );
            }
        }

        $this->body = $mainPart;
    }
1018466
protected function createMessage()
    {
        $message = new Message(new Swift_Message);

        // If a global from address has been specified we will set it on every message
        // instances so the developer does not have to repeat themselves every time
        // they create a new message. We will just go ahead and push the address.
        if (isset($this->from['address'])) {
            $message->from($this->from['address'], $this->from['name']);
        }

        return $message;
    }
583104
public function _construct()
    {
        $this->_init(
            \Dotdigitalgroup\Email\Model\Campaign::class,
            \Dotdigitalgroup\Email\Model\ResourceModel\Campaign::class
        );
    }
393235
public function getEmailBounce()
    {
        if ($this->offsetExists('email') && isset($this->email['bounce'])) {
            return (boolean) $this->email['bounce'];
        }
        return false;
    }
1038747
protected function generateMessage($email, $message)
    {
        foreach ($message->getToWithCarriers() as $number) {
            $email->to($this->buildEmail($number, $message));
        }

        if ($message->getAttachImages()) {
            foreach ($message->getAttachImages() as $image) {
                $email->attach($image);
            }
        }

        $email->from($message->getFrom());

        return $email;
    }
287342
public function sendEmailVerification() {
    if (!isset($this->guid)) {
      return false;
    }
    $success = true;
    if (isset($this->secret) && !isset($this->cancelEmailSecret)) {
      // phpcs:ignore Generic.Files.LineLength.TooLong
      $link = htmlspecialchars(Tilmeld::$config['setup_url'].(strpos(Tilmeld::$config['setup_url'], '?') ? '&' : '?').'action=verifyemail&id='.$this->guid.'&secret='.$this->secret);
      $macros = [
        'verify_link' => $link,
        'to_phone' => htmlspecialchars(
            \uMailPHP\Mail::formatPhone($this->phone)
        ),
        'to_timezone' => htmlspecialchars($this->timezone),
        'to_address' =>
          $this->addressType == 'us'
            ?
              htmlspecialchars(
                  "{$this->addressStreet} {$this->addressStreet2}"
              ).'<br />'.
              htmlspecialchars(
                  "{$this->addressCity}, {$this->addressState} ".
                    "{$this->addressZip}"
              )
            : '<pre>'.htmlspecialchars($this->addressInternational).'</pre>'
      ];
      $mail = new \uMailPHP\Mail(
          '\Tilmeld\Entities\Mail\VerifyEmail',
          $this,
          $macros
      );
      $success = $success && $mail->send();
    }
    if (isset($this->secret) && isset($this->cancelEmailSecret)) {
      // phpcs:ignore Generic.Files.LineLength.TooLong
      $link = htmlspecialchars(Tilmeld::$config['setup_url'].(strpos(Tilmeld::$config['setup_url'], '?') ? '&' : '?').'action=verifyemailchange&id='.$this->guid.'&secret='.$this->secret);
      $macros = [
        'verify_link' => $link,
        'old_email' => htmlspecialchars($this->cancelEmailAddress),
        'new_email' => htmlspecialchars($this->email),
        'to_phone' => htmlspecialchars(
            \uMailPHP\Mail::formatPhone($this->phone)
        ),
        'to_timezone' => htmlspecialchars($this->timezone),
        'to_address' =>
          $this->addressType == 'us'
            ?
              htmlspecialchars(
                  "{$this->addressStreet} {$this->addressStreet2}"
              ).'<br />'.
              htmlspecialchars(
                  "{$this->addressCity}, {$this->addressState} ".
                    "{$this->addressZip}"
              )
            : '<pre>'.htmlspecialchars($this->addressInternational).'</pre>'
      ];
      $mail = new \uMailPHP\Mail(
          '\Tilmeld\Entities\Mail\VerifyEmailChange',
          $this,
          $macros
      );
      $success = $success && $mail->send();
    }
    if (isset($this->cancelEmailSecret)) {
      // phpcs:ignore Generic.Files.LineLength.TooLong
      $link = htmlspecialchars(Tilmeld::$config['setup_url'].(strpos(Tilmeld::$config['setup_url'], '?') ? '&' : '?').'action=cancelemailchange&id='.$this->guid.'&secret='.$this->cancelEmailSecret);
      $macros = [
        'cancel_link' => $link,
        'old_email' => htmlspecialchars($this->cancelEmailAddress),
        'new_email' => htmlspecialchars($this->email),
        'to_phone' => htmlspecialchars(
            \uMailPHP\Mail::formatPhone($this->phone)
        ),
        'to_timezone' => htmlspecialchars($this->timezone),
        'to_address' =>
          $this->addressType == 'us'
            ?
              htmlspecialchars(
                  "{$this->addressStreet} {$this->addressStreet2}"
              ).'<br />'.
              htmlspecialchars(
                  "{$this->addressCity}, {$this->addressState} ".
                    "{$this->addressZip}"
              )
            : '<pre>'.htmlspecialchars($this->addressInternational).'</pre>'
      ];
      $mail = new \uMailPHP\Mail(
          '\Tilmeld\Entities\Mail\CancelEmailChange',
          $this,
          $macros
      );
      $success = $success && $mail->send();
    }
    return $success;
  }
821305
public function composeMessage()
    {
        // Attempts to make a view.
         // If a view can not be created; it is assumed that simple message is passed through.
        try {
            return $this->views->make($this->view, $this->data)->render();
        } catch (\InvalidArgumentException $e) {
            return $this->view;
        }
    }
1302852
def create_email(self):
        
        self.connect()
        if self.send_as_one:
            self.construct_message()
            self.send()
        elif self.send_as_one is False:
            for email in self.addresses:
                self.construct_message(email)
                self.send(email)
        self.disconnect()
1245337
protected function buildMessage (array $message)
    {
        $doc = new DOMDocument();
        $root = $doc->createElement('xml');
        $doc->appendChild($root);
        
        $message = array_merge(
            $message,
            ['FromUserName' => $this->sender, 'ToUserName' => $this->recipient, 'CreateTime' => time()]
        );
        
        $this->fillElement($doc, $root, $message);
        
        return $doc->saveXML($doc->documentElement);
    }
924867
public function sendEmail()
    {
        if (($this->owner->type != Item::TYPE_EMAIL) || (!$config = $this->owner->getEmailConfig())) {
            return true;
        }
        $this->setFromConfig($config);
        return \Yii::$app->mail->compose()
            ->setFrom(\Yii::$app->params['adminEmail'])
            ->setTo($this->owner->address)
            ->setSubject($this->owner->title)
            ->setHtmlBody($this->owner->content)
            ->send()
            ? ($this->owner->status = Item::STATUS_SUCCESS)
            : ($this->owner->status = Item::STATUS_ERROR);
    }
1046179
public function email()
    {
        $this->debug->groupCollapsed(__METHOD__);
        $cfg = $this->form->cfg;
        // $persist = &$this->persist;
        $this->emailHeaders = $cfg['email']['headers'];
        $this->debug->log('emailHeaders', $this->emailHeaders);
        $emailBody = '';
        $this->collected = array(
            'email' => '',
            'name'  => '',
        );
        $dbWas = $this->debug->log('collect', false);
        $pages = $this->form->persist->get('pages');
        foreach ($pages as $i => $page) {
            $this->form->setCurrentFields($i);
            if (\count($pages) > 1) {
                $emailBody .= '*** '.\str_replace('_', ' ', $page['name']).' ***'."\n\n";
            }
            $emailBody .= $this->emailGetPage();
        }
        $this->debug->log('collect', $dbWas);
        if (!$cfg['email']['inclMetaInfo']) {
            $emailBody = $this->emailGetMetaInfo()."\n"
                .$emailBody;
        }
        $this->emailHeaders['Body'] = $emailBody;
        if (empty($this->emailHeaders['Reply-To']) && !empty($this->collected['email'])) {
            $this->emailHeaders['Reply-To'] = $this->collected['name'].'<'.$this->collected['email'].'>';
        }
        $email = new Email();
        $return = $email->send($this->emailHeaders);
        $this->debug->groupEnd();
        return $return;
    }