19 declare(strict_types=1);
42 $this->repository_tree = $DIC->repositoryTree();
43 $this->sender_factory = $DIC->mail()->mime()->senderFactory();
48 $this->lang_variables_as_fallback = $a_status;
68 $this->u_password = $a_pwd;
82 $this->attachments = [];
85 $this->
user = $a_user;
90 if ($permanent_link_target ===
'') {
92 'Permanent link target must not be empty' 107 $this->u_password =
'';
108 $this->permanent_link_target =
null;
117 foreach ([
'lang',
'subject',
'body',
'sal_f',
'sal_g',
'sal_m',
'type'] as $key) {
118 if (!isset($mail_data[$key])) {
119 $mail_data[$key] =
'';
123 $mail_data[
'subject'] = trim($mail_data[
'subject']);
124 $mail_data[
'body'] = trim($mail_data[
'body']);
134 if (!isset($this->amail[$a_lang]) || !is_array($this->amail[$a_lang])) {
140 return $this->amail[$a_lang];
152 $path_to_tile =
'/' . implode(
155 static fn(
string $path_part):
string => trim($path_part,
'/'),
157 $fs->getAbsolutePath(),
177 throw new RuntimeException(
'A user instance must be passed when sending emails');
188 if ($amail[
'body'] ===
'' || $amail[
'subject'] ===
'') {
189 $fallback_language =
'en';
191 $lang = $this->
settings->get(
'language', $fallback_language);
199 $mail_subject = $tmp_lang->txt(
'reg_mail_subject');
203 $tmp_lang->loadLanguageModule(
'registration');
209 $timelimit =
"\n" . sprintf($tmp_lang->txt(
'reg_mail_body_timelimit'), $timelimit) .
"\n\n";
213 $mail_body = $tmp_lang->txt(
'reg_mail_body_salutation') .
' ' . $user->
getFullname() .
",\n\n" .
214 $tmp_lang->txt(
'reg_mail_body_text1') .
"\n\n" .
215 $tmp_lang->txt(
'reg_mail_body_text2') .
"\n" .
216 ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID .
"\n";
217 $mail_body .= $tmp_lang->txt(
'login') .
': ' . $user->
getLogin() .
"\n";
218 $mail_body .= $tmp_lang->txt(
'passwd') .
': ' . $this->u_password .
"\n";
219 $mail_body .=
"\n" . $timelimit;
220 $mail_body .= $tmp_lang->txt(
'reg_mail_body_text3') .
"\n\r";
221 $mail_body .= $user->getProfileAsString($tmp_lang);
231 $mmail->From($this->sender_factory->system());
232 $mmail->Subject($mail_subject,
true);
234 $mmail->Body($mail_body);
236 foreach ($this->attachments as
$filename => $display_name) {
237 $mmail->Attach(
$filename,
'',
'attachment', $display_name);
248 $settings = $DIC->settings();
249 $mustache_factory = $DIC->mail()->mustacheFactory();
254 $replacements[
'MAIL_SALUTATION'] = $mustache_factory->getBasicEngine()->render(
256 'f' => trim((
string) $a_amail[
'sal_f']),
257 'm' => trim((
string) $a_amail[
'sal_m']),
258 default => trim((
string) $a_amail[
'sal_g']),
266 $replacements[
'LOGIN'] = $a_user->
getLogin();
268 $replacements[
'LAST_NAME'] = $a_user->
getLastname();
270 $replacements[
'EMAIL'] = $a_user->
getEmail();
273 $replacements[
'ILIAS_URL'] = ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID;
275 $replacements[
'ADMIN_MAIL'] = $settings->get(
'admin_email');
286 $replacements[
'TIMELIMIT'] = $timelimit;
290 $replacements[
'IF_TARGET'] =
false;
291 if ($this->permanent_link_target !==
null) {
292 $tarr = explode(
'_', $this->permanent_link_target);
293 if ($this->repository_tree->isInTree((
int) $tarr[1])) {
296 if ($type === $tarr[0]) {
303 $replacements[
'IF_TARGET'] =
true;
308 return $mustache_factory->getBasicEngine()->render($a_string, $replacements);
311 public function addAttachment(
string $a_filename,
string $a_display_name): void
313 $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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readAccountMail(string $a_lang)
ensureValidMailDataShape(array $mail_data)
setAttachConfiguredFiles(bool $attach_configured_files)
getFullname(int $a_max_strlen=0)
setPermanentLinkTarget(?string $permanent_link_target)
areLangVariablesUsedAsFallback()
static _lookupObjId(int $ref_id)
replacePlaceholders(string $a_string, ilObjUser $a_user, array $a_amail, string $a_lang)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
bool $attach_configured_files
setUserPassword(string $a_pwd)
static _lookupTitle(int $obj_id)
static _lookupNewAccountMail(string $a_lang)
readonly ilMailMimeSenderFactory $sender_factory
useLangVariablesAsFallback(bool $a_status)
addAttachment(string $a_filename, string $a_display_name)
readonly ilSetting $settings
readonly ilTree $repository_tree
string $permanent_link_target
setUser(ilObjUser $a_user)
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)
addAttachments(array $mail_data)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.