Browse Source

Add a MailNotify class with usage of Twig

tags/1.0.0
Victor Laborie 1 year ago
parent
commit
20e32c4149

+ 1
- 2
htdocs/lib/class.ldapdomain.php View File

@@ -95,8 +95,7 @@ class LdapDomain extends LdapServer {
$error = ldap_error($this->conn);
throw new Exception("Erreur dans l'ajout du compte : $error");
}
mail($mail, 'Premier message',"Mail d'initialisation du compte.");
//mailnotify($info,$this->getname(),$password);
MailNotify::addAccount($this->domain, $mail, $name, $password);
}

public function addAlias($name,$active=false,$mailaccept=array(),$maildrop=array()) {

+ 1
- 1
htdocs/lib/class.ldapserver.php View File

@@ -117,7 +117,7 @@ class LdapServer {
throw new Exception("Erreur dans l'ajout du domaine : $error");
}
Logger::info('domain '.$name.' added', $this->login);
//domainnotify($name);
MailNotify::addDomain($name);
}

public function delDomain($name) {

+ 34
- 0
htdocs/lib/class.mailnotify.php View File

@@ -0,0 +1,34 @@
<?php

class MailNotify {
private static $twig, $adminmail;

public static function configure($config) {
$loader = new Twig_Loader_Filesystem('tpl/mail');
self::$twig = new Twig_Environment($loader, array(
'cache' => false
));

self::$adminmail = !empty($config['mail']) ? $config['mail'] : 'root@localhost';
}

public static function addDomain($domain) {
$headers = "From: ".self::$adminmail;

# Notification mail to admin mail
$mail_notif = self::$twig->render('domain/add_notif.txt.twig', array('domain' => $domain));
mail(self::$adminmail, 'Création du domaine '.$domain, $mail_notif, $headers);
}

public static function addAccount($domain, $mail, $name, $password) {
$headers = "From: ".self::$adminmail;

# Welcome mail for account initialization
$mail_init = self::$twig->render('account/init.txt.twig', array('mail' => $mail, 'name' => $name));
mail($mail, 'Bienvenue !', $mail_init, $headers);

# Notification mail to admin mail
$mail_notif = self::$twig->render('account/add_notif.txt.twig', array('mail' => $mail, 'name' => $name, 'password' => $password));
mail(self::$adminmail, 'Création du compte '.$mail, $mail_notif, $headers);
}
}

+ 6
- 1
htdocs/lib/config.php View File

@@ -4,9 +4,14 @@ define("VERSION", "2.0.0");

spl_autoload_register(function ($class) {
$class = strtolower($class);
include_once("lib/class.$class.php");
if (file_exists("lib/class.$class.php")) {
require_once("lib/class.$class.php");
}
});

require_once 'Twig/autoload.php';

$config = parse_ini_file('../config/config.ini', true);

Logger::configure($config['log']);
MailNotify::configure($config['global']);

+ 11
- 0
htdocs/tpl/mail/account/add_notif.txt.twig View File

@@ -0,0 +1,11 @@
{# Notification mail send to global config mail address #}
Bonjour,

Le compte mail "{{ name | escape }}" vient d'être créé.

Identifiant : {{ mail | escape }}
Mot de passe : {{ password | escape }}

Cordialement,
--
L'équipe informatique

+ 4
- 0
htdocs/tpl/mail/account/init.txt.twig View File

@@ -0,0 +1,4 @@
{# Welcome mail send for account initialization #}
Bienvenue {{ name | escape }},

Votre adresse {{ mail | escape }} est maintenant activé.

+ 10
- 0
htdocs/tpl/mail/domain/add_notif.txt.twig View File

@@ -0,0 +1,10 @@
{# Notification mail send to global config mail address #}
Bonjour,

Un nouveau domaine vient d'être créé : {{ domain | escape }}

Assurez vous que la configuration DNS et MX soit bien en place.

Cordialement,
--
L'équipe informatique

Loading…
Cancel
Save