1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| # Variables
# Changer ladresse email de lexpéditeur
$MSender = romain.dupont@toto.fr
# Changer ladresse IP du serveur de messagerie
$MServer = « 192.168.0.1″
# Indiquer le chemin LDAP de votre annuaire
$Ldappath = « OU=Utilisateurs,DC=msreport,DC=intra »
# Fonction pour générer le mail
function Send-SMTPmail($to, $from, $subject, $body, $attachment, $cc, $bcc, $port, $timeout, $smtpserver, [switch] $html, [switch] $alert)
{
if ($smtpserver -eq $null) {$smtpserver = $MServer}
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
if ($port -ne $null) {$mailer.port = $port}
if ($timeout -ne $null) {$mailer.timeout = $timeout}
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
if ($html) {$msg.IsBodyHTML = $true}
if ($cc -ne $null) {$msg.cc.add($cc)}
if ($bcc -ne $null) {$msg.bcc.add($bcc)}
if ($alert) {$msg.Headers.Add(« message-id », « <3bd50098e401463aa228377848493927-1> »)}
if ($attachment -ne $null)
{
$attachment = new-object Net.Mail.Attachment($attachment)
$msg.attachments.add($attachment)
}
$mailer.send($msg)
} |
Partager