19 declare(strict_types=1);
52 $this->senderFactory = $DIC->mail()->mime()->senderFactory();
57 $this->lang_variables_as_fallback = $a_status;
77 $this->u_password = $a_pwd;
91 $this->attachments = [];
94 $this->
user = $a_user;
99 if ($permanent_link_target ===
'') {
101 'Permanent link target must not be empty' 116 $this->u_password =
'';
117 $this->permanent_link_target = null;
126 foreach ([
'lang',
'subject',
'body',
'sal_f',
'sal_g',
'sal_m',
'type'] as $key) {
127 if (!isset($mailData[$key])) {
128 $mailData[$key] =
'';
132 $mailData[
'subject'] = trim($mailData[
'subject']);
133 $mailData[
'body'] = trim($mailData[
'body']);
143 if (!isset($this->amail[$a_lang]) || !is_array($this->amail[$a_lang])) {
149 return $this->amail[$a_lang];
162 $pathToFile =
'/' . implode(
'/',
array_map(
static function (
string $pathPart):
string {
163 return trim($pathPart,
'/');
165 $fs->getAbsolutePath(),
184 throw new RuntimeException(
'A user instance must be passed when sending emails');
195 if ($amail[
'body'] ===
'' || $amail[
'subject'] ===
'') {
196 $fallback_language =
'en';
198 $lang = $this->
settings->get(
'language', $fallback_language);
206 $mail_subject = $tmp_lang->txt(
'reg_mail_subject');
210 $tmp_lang->loadLanguageModule(
'registration');
216 $timelimit =
"\n" . sprintf($tmp_lang->txt(
'reg_mail_body_timelimit'), $timelimit) .
"\n\n";
220 $mail_body = $tmp_lang->txt(
'reg_mail_body_salutation') .
' ' . $user->
getFullname() .
",\n\n" .
221 $tmp_lang->txt(
'reg_mail_body_text1') .
"\n\n" .
222 $tmp_lang->txt(
'reg_mail_body_text2') .
"\n" .
223 ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID .
"\n";
224 $mail_body .= $tmp_lang->txt(
'login') .
': ' . $user->
getLogin() .
"\n";
225 $mail_body .= $tmp_lang->txt(
'passwd') .
': ' . $this->u_password .
"\n";
226 $mail_body .=
"\n" . $timelimit;
227 $mail_body .= $tmp_lang->txt(
'reg_mail_body_text3') .
"\n\r";
228 $mail_body .= $user->getProfileAsString($tmp_lang);
238 $mmail->From($this->senderFactory->system());
239 $mmail->Subject($mail_subject,
true);
241 $mmail->Body($mail_body);
243 foreach ($this->attachments as
$filename => $display_name) {
244 $mmail->Attach(
$filename,
'',
'attachment', $display_name);
255 $tree = $DIC->repositoryTree();
257 $mustache_factory = $DIC->mail()->mustacheFactory();
262 $replacements[
'MAIL_SALUTATION'] = $mustache_factory->getBasicEngine()->render(
264 'f' => trim((
string) $a_amail[
'sal_f']),
265 'm' => trim((
string) $a_amail[
'sal_m']),
266 default => trim((
string) $a_amail[
'sal_g']),
274 $replacements[
'LOGIN'] = $a_user->
getLogin();
276 $replacements[
'LAST_NAME'] = $a_user->
getLastname();
278 $replacements[
'EMAIL'] = $a_user->
getEmail();
281 $replacements[
'ILIAS_URL'] = ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID;
283 $replacements[
'ADMIN_MAIL'] =
$ilSetting->get(
'admin_email');
294 $replacements[
'TIMELIMIT'] = $timelimit;
298 $replacements[
'IF_TARGET'] =
false;
299 if ($this->permanent_link_target !== null) {
300 $tarr = explode(
'_', $this->permanent_link_target);
304 if ($type === $tarr[0]) {
311 $replacements[
'IF_TARGET'] =
true;
316 return $mustache_factory->getBasicEngine()->render($a_string, $replacements);
319 public function addAttachment(
string $a_filename,
string $a_display_name): void
321 $this->attachments[$a_filename] = $a_display_name;
send()
Sends the mail with its object properties as MimeMail It first tries to read the mail body...
shouldAttachConfiguredFiles()
bool $lang_variables_as_fallback
readonly ilMailMimeSenderFactory $senderFactory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readAccountMail(string $a_lang)
setAttachConfiguredFiles(bool $attachConfiguredFiles)
getFullname(int $a_max_strlen=0)
ensureValidMailDataShape(array $mailData)
setPermanentLinkTarget(?string $permanent_link_target)
addAttachments(array $mailData)
areLangVariablesUsedAsFallback()
static _lookupObjId(int $ref_id)
replacePlaceholders(string $a_string, ilObjUser $a_user, array $a_amail, string $a_lang)
setUserPassword(string $a_pwd)
static _lookupTitle(int $obj_id)
static _lookupNewAccountMail(string $a_lang)
useLangVariablesAsFallback(bool $a_status)
addAttachment(string $a_filename, string $a_display_name)
readonly ilSetting $settings
string $permanent_link_target
readonly ilTree $repositoryTree
setUser(ilObjUser $a_user)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ilObjUser $user=null)
Format a period of two dates Shows: 14.
bool $attachConfiguredFiles
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)