As part of my work placement, I need to use PowerShell to browse a mailbox and retrieve information from it. I have no problems with this. However, it is the secondary mailbox that the script has to browse and it only browses the main mailbox. Do you have any ideas? I’ve included the code just below. Thank you in advance for your answers. Have a nice day.
# Initialise un compteur qui va servir pour la boucle qui gère le stockage
$cpt = 0
$contain = ""
# Connexion à la boite mail + récupération des mails
$olFolderInbox = 6
$outlook = new-object -com outlook.application
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($outlook)
# Boucle permettant de parcourir la boite mail et de récupérer les informations sur la totalité des mails
$inbox.items | foreach {
$Expediteur = $_.SenderName
$Recepteur = $_.To
$DateReception = $_.ReceivedTime
$Sujet = $_.Subject
$Contenu = $_.Body
$Fichier = $_.Attachments
# Grâce aux informations obtenus, on peut faire une condition permettant de prendre seulement les mails utiles au script
if ($Expediteur -Match ('Backup'))
{
$contain = $contain + $Contenu + "<br>" + "<br>"
}
}
# Variables
$to = "private mailbox"
$from = "private mailbox"
$smtpServer = "private SMTP server"
$encodingMail = [System.Text.Encoding]::UTF8
# Préparation du message email
$subject = "Log + message d'erreur"
$body = "
Bonjour,
<p> Voici les logs/erreurs.<br>"
$body = $body + "<br>$($contain)"
$body = $body + "<br>"
$body = $body + "<br><br>Cordialement,<br><br>"
Send-MailMessage -to $to -From $from -Subject $subject -SmtpServer $smtpServer -BodyAsHtml $body -Encoding $encodingMail
New contributor
kylian35 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.