public static function sendEmail($args) { $isEncrypted = OC_App::isEnabled('files_encryption'); if (!$isEncrypted || isset($_POST['continue'])) { $continue = true; } else { $continue = false; } if (OC_User::userExists($_POST['user']) && $continue) { $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', '')); OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token)); // Hash the token again to prevent timing attacks $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); if (!empty($email)) { $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token)); $link = OC_Helper::makeURLAbsolute($link); $tmpl = new OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link, false); $msg = $tmpl->fetchPage(); $l = OC_L10N::get('core'); $from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); try { OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud'); } catch (Exception $e) { OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.'); } self::displayLostPasswordPage(false, true); } else { self::displayLostPasswordPage(true, false); } } else { self::displayLostPasswordPage(true, false); } }
public static function sendEmail($args) { if (OC_User::userExists($_POST['user'])) { $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', '')); OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token)); // Hash the token again to prevent timing attacks $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); if (!empty($email)) { $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token)); $link = OC_Helper::makeURLAbsolute($link); $tmpl = new OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link, false); $msg = $tmpl->fetchPage(); $l = OC_L10N::get('core'); $from = 'lostpassword-noreply@' . OCP\Util::getServerHost(); OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud'); echo 'Mailsent'; self::displayLostPasswordPage(false, true); } else { self::displayLostPasswordPage(true, false); } } else { self::displayLostPasswordPage(true, false); } }
/** * Send a mail to test the settings * @return array */ public function sendTestMail() { $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', ''); if (!empty($email)) { try { $this->mail->send($email, $this->userSession->getUser()->getDisplayName(), $this->l10n->t('test email settings'), $this->l10n->t('If you received this email, the settings seem to be correct.'), $this->defaultMailAddress, $this->defaults->getName()); } catch (\Exception $e) { return array('data' => array('message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings.')), 'status' => 'error'); } return array('data' => array('message' => (string) $this->l10n->t('Email sent')), 'status' => 'success'); } return array('data' => array('message' => (string) $this->l10n->t('You need to set your user email before being able to send test emails.')), 'status' => 'error'); }
/** * @brief Send an email while creating and assigning a task * @param Title of the task * @param Task description * @param Project ID to which the task belongs * @param To whom the task is assigned * @param Deadline for completing the task */ public static function sendTaskCreationMail($title, $desc, $pid, $member, $deadline) { try { $subject = 'You are assigned a task \'' . $title . '\''; $message = 'Hello ' . $member . ','; $message .= '<br /><p style="text-indent: 50px;" >'; $message .= 'You are assigned to the task \'' . $title . '\' under the project \'' . OC_Collaboration_Project::getProjectTitle($pid) . '\'.'; $message .= '<br /><p style="text-align: justify;" ><span style="font-weight: bold;" >'; $message .= 'Description: '; $message .= '</span>' . $desc . '<br /><br /><span style="font-weight: bold;" >'; $message .= 'Deadline: '; $message .= '</span>' . $deadline . '</p><br /><br />'; $message .= 'For further details, logon to your owncloud account.'; $message .= '<br /><br />'; \OC_Mail::send(OC_Preferences::getValue($member, 'settings', 'email'), $member, $subject, $message, OC_Config::getValue('mail_smtpname', ''), 'Owncloud Collaboration App', true); } catch (\Exception $e) { OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG); return false; } }
/** * Set the mail address of a user * * @NoAdminRequired * @NoSubadminRequired * * @param string $id * @param string $mailAddress * @return DataResponse * * TODO: Tidy up and write unit tests - code is mainly static method calls */ public function setMailAddress($id, $mailAddress) { // FIXME: Remove this static function call at some point… if ($this->userSession->getUser()->getUID() !== $id && !$this->isAdmin && !\OC_SubAdmin::isUserAccessible($this->userSession->getUser()->getUID(), $id)) { return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Forbidden'))), Http::STATUS_FORBIDDEN); } if ($mailAddress !== '' && !$this->mail->validateAddress($mailAddress)) { return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid mail address'))), Http::STATUS_UNPROCESSABLE_ENTITY); } $user = $this->userManager->get($id); if (!$user) { return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid user'))), Http::STATUS_UNPROCESSABLE_ENTITY); } // this is the only permission a backend provides and is also used // for the permission of setting a email address if (!$user->canChangeDisplayName()) { return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to change mail address'))), Http::STATUS_FORBIDDEN); } $this->config->setUserValue($id, 'settings', 'email', $mailAddress); return new DataResponse(array('status' => 'success', 'data' => array('username' => $id, 'mailAddress' => $mailAddress, 'message' => (string) $this->l10n->t('Email saved'))), Http::STATUS_OK); }
/** * Send a mail to test the settings */ public static function sendTestMail() { \OC_Util::checkAdminUser(); \OCP\JSON::callCheck(); $l = \OC::$server->getL10N('settings'); $email = \OC_Preferences::getValue(\OC_User::getUser(), 'settings', 'email', ''); if (!empty($email)) { $defaults = new \OC_Defaults(); try { \OC_Mail::send($email, \OC_User::getDisplayName(), $l->t('test email settings'), $l->t('If you received this email, the settings seem to be correct.'), \OCP\Util::getDefaultEmailAddress('no-reply'), $defaults->getName()); } catch (\Exception $e) { $message = $l->t('A problem occurred while sending the e-mail. Please revisit your settings.'); \OC_JSON::error(array("data" => array("message" => $message))); exit; } \OC_JSON::success(array("data" => array("message" => $l->t("Email sent")))); } else { $message = $l->t('You need to set your user email before being able to send test emails.'); \OC_JSON::error(array("data" => array("message" => $message))); } }
} $txtmsg = '<html><p>Hi, ' . $uid . ', <br><br>'; $txtmsg .= '<p>find your OTP Configuration<br>'; $txtmsg .= 'User Algorithm : ' . $mOtp->GetUserAlgorithm() . '<br>'; if ($mOtp->GetUserPrefixPin()) { $txtmsg .= 'User Pin : ' . $mOtp->GetUserPin() . '<br>'; } $txtmsg .= 'User Token Seed : ' . $UserTokenSeed . "<br>"; $txtmsg .= 'User Token Time Interval Or Last Event : ' . (strtolower($mOtp->GetUserAlgorithm()) === 'htop' ? $mOtp->GetUserTokenLastEvent() : $mOtp->GetUserTokenTimeInterval()) . "<br>"; $txtmsg .= 'Token Url Link : ' . $mOtp->GetUserTokenUrlLink() . "<br>"; $txtmsg .= 'With android token apps select base32 before input seed<br>'; $txtmsg .= '<img src="data:image/png;base64,' . base64_encode($mOtp->GetUserTokenQrCode($mOtp->GetUser(), '', 'binary')) . '"/><br><br>'; $txtmsg .= $l->t('<p>This e-mail is automatic, please, do not reply to it.</p></html>'); if ($mail !== NULL) { try { $result = OC_Mail::send($mail, $uid, '[' . getenv('SERVER_NAME') . "] - OTP", $txtmsg, 'Mail_Notification@' . getenv('SERVER_NAME'), 'Owncloud', 1); OCP\JSON::success(array("data" => array("message" => $l->t("email sent to " . $mail)))); } catch (Exception $e) { OCP\JSON::error(array("data" => array("message" => $l->t($e->getMessage())))); } } else { //echo "Email address error<br>"; OCP\JSON::error(array("data" => array("message" => $l->t("Email address error : " . $mail)))); } } else { if ($_POST && ($_POST["otp_action"] === "create_otp" || $_POST["otp_action"] === "replace_otp")) { if ($mOtp->CheckUserExists($uid) && $_POST["otp_action"] === "replace_otp") { if (!$mOtp->DeleteUser($uid)) { OCP\JSON::error(array("data" => array("message" => $l->t("error during deleting otp")))); return; }
/** * @brief Returns the default email address * @param string $user_part the user part of the address * @returns string the default email address * * Assembles a default email address (using the server hostname * and the given user part, and returns it * Example: when given lostpassword-noreply as $user_part param, * and is currently accessed via http(s)://example.com/, * it would return '*****@*****.**' */ public static function getDefaultEmailAddress($user_part) { $host_name = self::getServerHostName(); $defaultEmailAddress = $user_part . '@' . $host_name; if (\OC_Mail::ValidateAddress($defaultEmailAddress)) { return $defaultEmailAddress; } // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' return $user_part . '@localhost.localdomain'; }
/** * @dataProvider buildAsciiEmailProvider * @param $expected * @param $address */ public function testBuildAsciiEmail($expected, $address) { $actual = \OC_Mail::buildAsciiEmail($address); $this->assertEquals($expected, $actual); }
/** * Send a notification to one user * * @param string $user Username of the recipient * @param string $email Email address of the recipient * @param string $lang Selected language of the recipient * @param array $mailData Notification data we send to the user */ public function sendEmailToUser($user, $email, $lang, $mailData) { $l = $this->getLanguage($lang); $dataHelper = new DataHelper(\OC::$server->getActivityManager(), new ParameterHelper(new \OC\Files\View(''), $l), $l); $activityList = array(); foreach ($mailData as $activity) { $activityList[] = $dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], unserialize($activity['amq_subjectparams'])); } $alttext = new \OCP\Template('activity', 'email.notification', ''); $alttext->assign('username', $user); $alttext->assign('timeframe', $this->getLangForApproximatedTimeFrame($mailData[0]['amq_timestamp'])); $alttext->assign('activities', $activityList); $alttext->assign('owncloud_installation', \OC_Helper::makeURLAbsolute('/')); $emailText = $alttext->fetchPage(); try { \OC_Mail::send($email, $user, $l->t('Activity notification'), $emailText, $this->getSenderData('email'), $this->getSenderData('name')); } catch (\Exception $e) { \OCP\Util::writeLog('Activity', 'A problem occurred while sending the e-mail. Please revisit your settings.', \OCP\Util::ERROR); } }
/** * @dataProvider validateMailProvider * @param $address * @param $expected */ public function testValidateEmail($address, $expected) { $actual = \OC_Mail::validateAddress($address); $this->assertEquals($expected, $actual); }
<?php OC_JSON::checkLoggedIn(); OCP\JSON::callCheck(); $l = \OC::$server->getL10N('settings'); // Get data if (isset($_POST['email']) && OC_Mail::validateAddress($_POST['email'])) { $email = trim($_POST['email']); OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email); OC_JSON::success(array("data" => array("message" => $l->t("Email saved")))); } else { OC_JSON::error(array("data" => array("message" => $l->t("Invalid email")))); }
private static function sendEmail($msg, $action, $toUid) { $l = new OC_L10N('mailnotify'); $txtmsg = '<html><p>Hi, ' . $toUid . ', <br><br>'; $txtmsg .= '<p>' . $msg; $txtmsg .= $l->t('<p>This e-mail is automatic, please, do not reply to it.</p></html>'); if (self::db_get_mail_by_user($toUid) !== NULL) { $result = OC_Mail::send(self::db_get_mail_by_user($toUid), $toUid, '[' . getenv('SERVER_NAME') . "] - " . $action, $txtmsg, 'Mail_Notification@' . getenv('SERVER_NAME'), 'Owncloud', 1); } else { echo "Email address error<br>"; } }
/** * @param string $user * @throws \Exception */ protected function sendEmail($user) { if (!$this->userManager->userExists($user)) { throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); } $email = $this->config->getUserValue($user, 'settings', 'email'); if (empty($email)) { throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.')); } $token = $this->secureRandom->getMediumStrengthGenerator()->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER); $this->config->setUserValue($user, 'owncloud', 'lostpassword', $token); $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token)); $tmpl = new \OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link, false); $msg = $tmpl->fetchPage(); try { // FIXME: should be added to the container and injected in here \OC_Mail::send($email, $user, $this->l10n->t('%s password reset', array($this->defaults->getName())), $msg, $this->from, $this->defaults->getName()); } catch (\Exception $e) { throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.')); } }
protected function sendEmail($user, $proceed) { if ($this->isDataEncrypted && !$proceed) { throw new EncryptedDataException(); } if (!$this->userManager->userExists($user)) { throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure ' . 'your username is correct.')); } $token = hash('sha256', \OC_Util::generateRandomBytes(30)); // Hash the token again to prevent timing attacks $this->config->setUserValue($user, 'owncloud', 'lostpassword', hash('sha256', $token)); $email = $this->config->getUserValue($user, 'settings', 'email'); if (empty($email)) { throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.')); } $link = $this->getLink('core.lost.resetform', $user, $token); $tmpl = new \OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link, false); $msg = $tmpl->fetchPage(); try { // FIXME: should be added to the container and injected in here \OC_Mail::send($email, $user, $this->l10n->t('%s password reset', array($this->defaults->getName())), $msg, $this->from, $this->defaults->getName()); } catch (\Exception $e) { throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.')); } }