#! perl -w use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; use Win32::OLE qw( in ); my $Outlook = Win32::OLE->new('Outlook.Application', 'Quit'); my $ol = Win32::OLE::Const->Load($Outlook); Detach_files(); sub Detach_files { my $ns; #Dim ns As NameSpace my $Inbox; #Dim Inbox As MAPIFolder my $Item; #Dim Item As Object my $Atmt; #Dim Atmt As Attachment my $FileName; #Dim FileName As String my $i; #Dim i As Integer $ns = GetNamespace("MAPI"); #Set ns = GetNamespace("MAPI") $Inbox = $ns->GetDefaultFolder(olFolderInbox); #Set Inbox = ns.GetDefaultFolder(olFolderInbox) #Undefined subroutine &main::GetNamespace called at detach_files.pl line 102.# I get this error message for the line above. $i = 0; # 'Check Inbox for messages and exit of none found if ($Inbox->Items->{Count} == 0) { return; #I don't know how to deal with this #Exit Sub } #' Check each message for attachments foreach (in $Inbox->Items){ #For Each Item In Inbox.Items #' Save any attachments found foreach (in $Atmt->Item->Attachments){ #For Each Atmt In Item.Attachments # ' This path must exist! Change folder name as necessary. if ($FileName =~ /Flat_file_/){ $FileName = "G:\\Input\\". "$_"; $Atmt->SaveAsFile($FileName); # Atmt.SaveAsFile FileName $i = $i + 1; } #End If } #Next Atmt } # 'Clear memory undef $Atmt; #Atmt = Nothing undef $Item; #Set Item = Nothing undef $ns; #Set ns = Nothing return; #Exit Sub } #End Sub