Email the output of the job, if any.

@return bool
495155
private function emailOutput()
    {
        if (! count($this->outputTo) || ! count($this->emailTo)) {
            return false;
        }

        if (isset($this->emailConfig['ignore_empty_output']) &&
            $this->emailConfig['ignore_empty_output'] === true &&
            empty($this->output)
        ) {
            return false;
        }

        $this->sendToEmails($this->outputTo);

        return true;
    }
799535
public function execute()
    {
        $addresses = $this->getEmailAddresses();

        // Without some email addresses in the yml file then we
        // can't do anything.
        if (count($addresses) == 0) {
            return false;
        }

        $buildStatus  = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
        $projectName  = $this->build->getProject()->getTitle();

        try {
            $view = $this->getMailTemplate();
        } catch (Exception $e) {
            $this->phpci->log(
                sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']),
                LogLevel::WARNING
            );
            $view = $this->getDefaultMailTemplate();
        }

        $view->build = $this->build;
        $view->project = $this->build->getProject();

        $layout = new View('Email/layout');
        $layout->build = $this->build;
        $layout->project = $this->build->getProject();
        $layout->content = $view->render();
        $body = $layout->render();

        $sendFailures = $this->sendSeparateEmails(
            $addresses,
            sprintf("PHPCI - %s - %s", $projectName, $buildStatus),
            $body
        );

        // This is a success if we've not failed to send anything.
        $this->phpci->log(Lang::get('n_emails_sent', (count($addresses) - $sendFailures)));
        $this->phpci->log(Lang::get('n_emails_failed', $sendFailures));

        return ($sendFailures === 0);
    }
1155894
public function send()
    {
        $oxEMail = oxNew(\OxidEsales\Eshop\Core\Email::class);
        $blSend = $oxEMail->sendNewsletterMail($this, $this->_oUser, $this->oxnewsletter__oxsubject->value);

        return $blSend;
    }
543869
protected function _send()
	{
		$message = $this->build_message();

		logger(\Fuel::L_INFO, 'To: '.static::format_addresses($this->to), 'Email NoOp driver');
		logger(\Fuel::L_INFO, 'Subject: '.$this->subject, 'Email NoOp driver');
		logger(\Fuel::L_INFO, 'Header: '.$message['header'], 'Email NoOp driver');
		logger(\Fuel::L_INFO, 'Body: '.$message['body'], 'Email NoOp driver');

		return true;
	}
280800
protected function send()
    {
        $this->logger->info(sprintf('Submitting to %s', Jobs::URL));

        try {
            $response = $this->api->send();
            $message = $response
                ? sprintf('Finish submitting. status: %s %s', $response->getStatusCode(), $response->getReasonPhrase())
                : 'Finish dry run';

            $this->logger->info($message);

            if ($response instanceof Response) {
                $this->logResponse($response);
            }

            return true;
        } catch (\GuzzleHttp\Exception\ConnectException $e) {
            // connection error
            $message = sprintf("Connection error occurred. %s\n\n%s", $e->getMessage(), $e->getTraceAsString());
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            // 422 Unprocessable Entity
            $response = $e->getResponse();
            $message = sprintf('Client error occurred. status: %s %s', $response->getStatusCode(), $response->getReasonPhrase());
        } catch (\GuzzleHttp\Exception\ServerException $e) {
            // 500 Internal Server Error
            // 503 Service Unavailable
            $response = $e->getResponse();
            $message = sprintf('Server error occurred. status: %s %s', $response->getStatusCode(), $response->getReasonPhrase());
        }

        $this->logger->error($message);

        if (isset($response)) {
            $this->logResponse($response);
        }

        return false;
    }
1005887
protected function pushJobs() : bool
    {
        // Skip if no jobs currently in queue
        if (empty($this->jobQueues)) {
            return true;
        }

        // Run trough list of (idle) workers and check if there is a job in queue the worker can handle
        foreach ($this->workerStates as $workerId => $workerState) {
            if ($workerState !== Worker::WORKER_STATE_IDLE) {
                continue;
            }
            $jobData = $this->getJobFromQueue($workerId);
            if (empty($jobData)) {
                continue;
            }
            try {
                $this->workerStats[$workerId]++;
                $this->workerJobMap[$workerId] = $jobData['job_id'];
                $this->workerJobSocket->send($jobData['job_name'], \ZMQ::MODE_SNDMORE);
                $this->workerJobSocket->send($jobData['job_id'], \ZMQ::MODE_SNDMORE);
                $this->workerJobSocket->send($workerId, \ZMQ::MODE_SNDMORE);
                $this->workerJobSocket->send($jobData['payload']);
            } catch (\ZMQException $e) {
                $this->logger->error('Error sending job to worker: ' . $e->getMessage());
            }
        }

        return true;
    }
1130242
private function resultCallHasOutput()
    {
        if (!$this->result instanceof ExecutedStepResult) {
            return false;
        }

        return $this->result->getCallResult()->hasStdOut() || $this->result->getCallResult()->hasException();
    }
1159952
protected function output()
    {
        /*
        Constant Description
        LOG_EMERG   system is unusable
        LOG_ALERT   action must be taken immediately
        LOG_CRIT    critical conditions
        LOG_ERR     error conditions
        LOG_WARNING warning conditions
        LOG_NOTICE  normal, but significant, condition
        LOG_INFO    informational message
        LOG_DEBUG   debug-level message
        */

        $flags = LOG_PID;

        // log entries must follow standard UTC timezone settings
        putenv('TZ=UTC');

        // connect to syslog
        #$flags = $flags | LOG_PERROR;
        openlog($_SERVER['REQUEST_URI'], $flags, LOG_DAEMON);

        // first get content to local var
        $content = $this->getContentRaw();

        // iterate log content
        foreach ($content as $logEntry) {
            // convert our type to systems log type
            $type = $this->typeToSystemType($logEntry['type']);

            // log to syslog
            syslog($type, $logEntry['message']);
        }

        // so we can clear the existing log
        $this->clearContent();

        // close connection to syslog
        closelog();
    }
853310
public function send()
    {
        $stack = $this->getStack();

        if ($stack->count() == 0) {
            return false;
        }

        foreach ($stack as $mail) {

            if (!$mail->send()) {
                $this->errors[] = $mail->ErrorInfo;
            }
        
        }

        if (count($this->errors) > 0) {
            return false;
        }

        return true;
    }
195837
public function nextMail()
    {
        if ( $this->writer !== null )
        {
            fclose( $this->writer );
            $this->files[] = $this->path . $this->file;
            $this->writer = null;
        }
        $mail = $this->set->nextMail();
        if ( $mail === true || $this->hasMoreMailData === false )
        {
            $this->counter++;

            // Temporary file name for the mail source
            $this->file = getmypid() . '-' . time() . '-' . $this->counter;
            $writer = fopen( $this->path . $this->file, 'w' );
            if ( $writer !== false )
            {
                $this->writer = $writer;
            }
            return $mail;
        }
        return false;
    }
1215316
public function handleCompletion()
    {
        $member = $this->User;

        if ($member && $member->exists()) {
            $email = new Email();
            $email->setTo($member->Email);
            $email->setSubject('A deletion task requested by you has completed.');

            $message = sprintf('<p>Hi, %s</p>', $member->getTitle());
            $message .= sprintf('<p>Job %s has completed.</p>', $this->Title);
            $message .= sprintf('<p>%s records have been deleted.</p>', $this->totalSteps);
            $email->setBody($message);

            return $email->send();
        }
    }
501586
public function email(): void
    {
        $oInput     = Factory::service('Input');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $action     = $oInput->post('action');
        $sEmail     = trim($oInput->post('email'));
        $iId        = (int) $oInput->post('id') ?: null;

        switch ($action) {

            case 'add':
                $bIsPrimary  = (bool) $oInput->post('isPrimary');
                $bIsVerified = (bool) $oInput->post('isVerified');

                if ($oUserModel->emailAdd($sEmail, $iId, $bIsPrimary, $bIsVerified)) {
                    $sStatus  = 'success';
                    $sMessage = '"' . $sEmail . '" was added successfully. ';
                } else {
                    $sStatus  = 'error';
                    $sMessage = 'Failed to add email. ';
                    $sMessage .= $oUserModel->lastError();
                }
                break;

            case 'delete':
                if ($oUserModel->emailDelete($sEmail, $iId)) {
                    $sStatus  = 'success';
                    $sMessage = '"' . $sEmail . '" was deleted successfully. ';
                } else {
                    $sStatus  = 'error';
                    $sMessage = 'Failed to delete email "' . $sEmail . '". ';
                    $sMessage .= $oUserModel->lastError();
                }
                break;

            case 'makePrimary':
                if ($oUserModel->emailMakePrimary($sEmail, $iId)) {
                    $sStatus  = 'success';
                    $sMessage = '"' . $sEmail . '" was set as the primary email.';
                } else {
                    $sStatus  = 'error';
                    $sMessage = 'Failed to mark "' . $sEmail . '" as the primary address. ';
                    $sMessage .= $oUserModel->lastError();
                }
                break;

            case 'verify':
                //  Get the code for this email
                $aUserEmails = $oUserModel->getEmailsForUser($iId);
                $sCode       = '';

                foreach ($aUserEmails as $oUserEmail) {
                    if ($oUserEmail->email == $sEmail) {
                        $sCode = $oUserEmail->code;
                    }
                }

                if (!empty($sCode) && $oUserModel->emailVerify($iId, $sCode)) {
                    $sStatus  = 'success';
                    $sMessage = '"' . $sEmail . '" was verified successfully.';
                } elseif (empty($sCode)) {
                    $sStatus  = 'error';
                    $sMessage = 'Failed to mark "' . $sEmail . '" as verified. ';
                    $sMessage .= 'Could not determine email\'s security code.';
                } else {
                    $sStatus  = 'error';
                    $sMessage = 'Failed to mark "' . $sEmail . '" as verified. ';
                    $sMessage .= $oUserModel->lastError();
                }
                break;

            default:
                $sStatus  = 'error';
                $sMessage = 'Unknown action: "' . $action . '"';
                break;
        }

        $oSession = Factory::service('Session', 'nails/module-auth');
        $oSession->setFlashData($sStatus, $sMessage);
        redirect($oInput->post('return'));
    }
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;
    }
1078357
public function sendVerificationEmail()
    {
        if ($this->owner->exists()) {
            $controller = Injector::inst()->get("Users_Register_Controller");
            $subject = _t("Users.PleaseVerify", "Please verify your account");

            if (Users::config()->send_email_from) {
                $from = Users::config()->send_email_from;
            } else {
                $from = Email::config()->admin_email;
            }

            $email = Email::create();
            $email
                ->setFrom($from)
                ->setTo($this->owner->Email)
                ->setSubject($subject)
                ->setTemplate('UsersAccountVerification')
                ->populateTemplate(
                    ArrayData::create(
                        array(
                        "Link" => Controller::join_links(
                            $controller->AbsoluteLink("verify"),
                            $this->owner->ID,
                            $this->owner->VerificationCode
                        )
                        )
                    )
                );

            $email->send();

            return true;
        }

        return false;
    }
195537
public function render()
	{
		return $this->headers->toString().Net_Mail::$delimiter.Net_Mail::$delimiter.$this->content/*.PHP_EOL*/;
	}
1085238
public function sendEmail()
    {
        if (!$this->validate()) {
            return false;
        }

        /** @var \amnah\yii2\user\models\UserToken $userToken */
        $user = $this->getUser();
        $userToken = $this->module->model("UserToken");

        // calculate type based on user status
        if ($user->status == $user::STATUS_INACTIVE) {
            $type = $userToken::TYPE_EMAIL_ACTIVATE;
        } //elseif ($user->status == $user::STATUS_UNCONFIRMED_EMAIL) {
        else {
            $type = $userToken::TYPE_EMAIL_CHANGE;
        }

        // generate userToken and send email confirmation
        $userToken = $userToken::generate($user->id, $type);
        return $user->sendEmailConfirmation($userToken);
    }
482627
private function checkMail()
    {
        $this->configureMail();

        try {
            $this->sendMail();

            $result = $this->makeHealthyResult();
        } catch (\Exception $exception) {
            report($exception);

            $result = $this->makeResultFromException($exception);
        }

        $this->restoreMailConfiguration();

        return $result;
    }