Sign in to follow this  
Followers 0
Juvigy

Outlook Rules and Attachments issues

12 posts in this topic

When working with OutlookEx udf i get a strange error:

 

err.description is:     The operation failed.
err.windescription:    
err.number is:     80020009
err.lastdllerror is:     0
err.scriptline is:     1681
err.source is:     Microsoft Outlook
err.helpfile is:     
err.helpcontext is:     0

My script is 50 lines so this must be in some of the iclude files.

What i am trying to do:

I have a rule in outlook that should move a mail in my pst and run a exe file to download the attachment to a folder.

It all works for one mail. But when i receive 2 or 3 mails almost at the same time the script fails and downloads only one attachment.

I use:

$myItem2 = $myFolder[1].Items.GetLast()
$myItem3 = $myItem2.attachments(1)
$myItem3.saveasfile($Filepath & $myItem3.FileName )

And what happens is that when the rule move 3 mails and executes the exe file , the 3 exe files get one and the same mail and download only 1 attachment instead of 3. What can i do to pass somehow a parameter to the exe file on which mail to execute ?

Share this post


Link to post
Share on other sites



When the Outlook rule is defined to run a script then the object of the mail is passed as a parameter to the script.

This means you can directly access/process the item in your script.

Link


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Do u mean i should create a VBA in Outlook and do a -  Shellexecute(myexe.exe 'param1')  ?

Or convert my outoit to VBA and create it in outlook and dont use a autoit script?

Share this post


Link to post
Share on other sites

I've never done something like this myself. I would suggest the solution that is easier for you to implement.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sub SaveAttachment(MyMail As MailItem)

    Dim strID As String

    Dim objMail As Outlook.MailItem

    FilePath = "C:111"

    strID = MyMail.EntryID

    Set objMail = Application.Session.GetItemFromID(strID)

    If objMail.FileName = "222.xlsx" Then objMail.Attachments(1).SaveAsFile (FilePath & objMail.FileName)

    objMail.Attachments(1).SaveAsFile (FilePath & "111" & Month(Now()) & Day(Now()) & ".xlsx")

    Set objMail = Nothing

End Sub

 

This is the VBA script  that i created and attached to the rule. When i a new mail arrive , it is moved by the rule to a pst but it doesnt save the file.

Share this post


Link to post
Share on other sites

There is no property named "FileName" for a mailitem object.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I think you could strip down your code because the function gets the object of the mailitem:

Sub SaveAttachment(MyMail As MailItem)
    FilePath = "C:\111\"
    If MyMail.Attachments(1).FileName = "222.xlsx" Then MyMail.Attachments(1).SaveAsFile (FilePath & MyMail.FileName)
    MyMail.Attachments(1).SaveAsFile (FilePath & "111" & Month(Now()) & Day(Now()) & ".xlsx")
End Sub

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Great , after fixint the small mistakes it works now. Thanks for the help.

Just curious - can this be done with AutoIt somehow ? Rule to pass object to a AutoIT exe file ?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I have Outlook 2010 installed and it allows to run an application when a mail is received (in German: "Anwendung starten").

But unfortunately I don't know which parameters Outlook passes.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You mean a rule which starts an application ? This works , but how to pass mail object (or any object) to that application ?

Share this post


Link to post
Share on other sites

I don't know if Outlook passes the item that triggered the rule to the application. Compile an AutoIt script that writes the number and type of parameters to a MsgBox:

If $CmdLine[0] > 0 Then
    MsgBox(0, "Parameters", "# of parameters: " & $CmdLine[0] & "Typ of parameter 1: " & VarGetType($CmdLine[1]))
Else
    MsgBox(0, "Parameters", "No parameters passed!")
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I tested it - it doesnt pass parameters.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0