Question Outlook verifier si email envoyé

Plus d'informations
il y a 3 ans 3 mois - il y a 3 ans 3 mois #30201 par CASPAR
Bonjour aux pros de Powershell !

j'aurais besoin de déterminer si un message a bien été envoyé à un destinataire dans Outlook 2016.

Il me semble que la bonne méthode serait de vérifier si le dit message est bien dans le dossier éléments envoyés...

(Je ne vois pas d'autres moyens d'y parvenir ...!?) Voilà les informations que j'ai trouvées pour l'instant mais je coince sur la manière de lister les éléments du dossier éléments envoyés ...

Peut être pourriez vous m'aider en me donnant des conseils ou des exemples de code ?

En vous remerciant pour votre aide.

Jean-Marc
$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$namespace = $ol.getnamespace("mapi")
#$mapi.Accounts
#$mapi.AddressLists
#$mapi.Folders
#$mapi.Application
#$mapi.AutoDiscoverConnectionMode
#$mapi.AutoDiscoverXml
#$mapi.AutoDiscoverConnectionMode
#$mapi.Parent
#$mapi.folders 
#$mapi.Categories
#$mapi.folders
#$mapi.Parent
#$mapi.ExchangeConnectionMode
#$mapi.ExchangeMailboxServerName
#$mapi.ExchangeMailboxServerVersion
#$mapi.GetDefaultFolder(olFolderSentMail)

#olFolderSentMail
#olFolderDeletedItems
#olFolderOutbox
#olFolderSentMail
#olFolderInbox
#olFolderCalendar
#olFolderContacts
#olFolderJournal
#olFolderNotes
#olFolderTasks
#olFolderDrafts
#olPublicFoldersAllPublicFolders
#olFolderConflicts
#olFolderSyncIssues
#olFolderLocalFailures
#olFolderServerFailures
#olFolderJunk
#olFolderRssFeeds
#olFolderToDo
#olFolderManagedEmail
#olFolderSuggestedContacts


$inbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$emails = $inbox.Items | Where-Object {$_.Subject -like $subjectComparisonExpression}
#The $emails variable will contain a list of just those emails that were sent from SSRS.  Now, for each of those, we can apply some processing.  For instance:
# Process the reports by recipient
ForEach ($email in $emails)
{
    # Look at all the attachments in a single email
    ForEach ($attach in $email.Attachments)
    {
        # Not the most robust way to do it, but extract only the first pdf.. there shouldn't be more than one anyway
        if ($attach.filename.contains("pdf"))
        {

             # Set the customer filename and paths and save off their report

             # Save the main file

          # Prepare outgoing emails (see following article section)
     } } }
     
     $template = get-childitem $emailTemplatePath -Filter "$emailTemplatePattern$customer.oft"
            if ((Test-Path $template.FullName) -eq $true) # Make sure there's a template to use
            {
                # Create the email from a template
                $emailToCustomer = $outlook.CreateItemFromTemplate($template.FullName.ToString())

                # Expand the contact groups
                #  Start with the To line
                $toListOriginal = $emailToCustomer.To
                $toListNew = $null
                $contacts = $namespace.GetDefaultFolder($olFolderContacts).Items  # All the contacts in outlook

                foreach ($to in $toListOriginal) # Enumerate the list of To's
                {
                    $toContacts = $contacts.Item($to)
                    for ($i = 1; $i -le $toContacts.MemberCount; $i++) 
                    {  
                        $toContact = $toContacts.GetMember($i)
                        [array]$toListNew = $toListNew + $toContact
                    } 
                }

                # Expand the CC line
                $ccListOriginal = $emailToCustomer.CC
                $ccListNew = $null
                $contacts = $namespace.GetDefaultFolder($olFolderContacts).Items  # All the contacts in outlook

                foreach ($cc in $ccListOriginal) # Enumerate the list of CC's
                {
                    $ccContacts = $contacts.Item($cc)
                    for ($i = 1; $i -le $ccContacts.MemberCount; $i++) 
                    {  
                        $ccContact = $ccContacts.GetMember($i)
                        [array]$ccListNew = $ccListNew + $ccContact
                    } 
                }

                # Convert to string
                if ([string]::IsNullOrEmpty($toListNew) -eq $false)
                {
                    $toListFinal = $null
                    foreach ($to in $toListNew) { $toListFinal = $toListFinal + $to.Address + ";" }
                    $toListFinal = $toListFinal.Substring(0, $toListFinal.Length - 1)  # Trim final ;
                    $emailToCustomer.To = $toListFinal
                }

                if ([string]::IsNullOrEmpty($ccListNew) -eq $false)
                {
                    $ccListFinal = $null
                    foreach ($cc in $ccListNew) { $ccListFinal = $ccListFinal + $cc.Address + ";" }
                    $ccListFinal = $ccListFinal.Substring(0, $ccListFinal.Length - 1)  # Trim final ;
                    $emailToCustomer.CC = $ccListFinal
                }
                
                # Customize the rest of the message as needed
                $emailToCustomer.Attachments.Add($fileFullPath) | Out-Null
                $emailToCustomer.HTMLBody = $emailToCustomer.HTMLBody.Replace("[Month]", $priorMonth)
                $emailToCustomer.HTMLBody = $emailToCustomer.HTMLBody.Replace("[Year]", $priorYear)
                $emailToCustomer.Save()
            }
Dernière édition: il y a 3 ans 3 mois par Arnaud Petitjean. Raison: Mise en forme du code

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 3 mois #30204 par Arnaud Petitjean
Bonjour Caspar / Loxito ;) (je ne sais pas trop)

Pour moi la meilleure méthode serait de regarder dans les logs du serveur Exchange... Mais je ne sais pas si tu es l'administrateur Exchange de ta société ?

Pourrais-tu nous dire quel est le réel objectif derrière ton besoin ? Cela nous permettrait de peut-être t'aiguiller vers une autre solution ?

En effet, la manipulation de l'objet COM Outlook n'a pas l'air des plus évidentes.

Arnaud

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.068 secondes
Propulsé par Kunena