Jump to content

Outlook UDF


Wooltown
 Share

Recommended Posts

Hi,

Here is a small piece of code which I use. (Tested with outlook 2003, with the proper permissions to read the other mailbox!)

This code saves an attachement in a mail from a different mailbox (it only saves attachements with the name brief.doc)

#Include <Array.au3>    
#Include <File.au3>             

local $teller

;$teller=Opslaanbijlagen("Caixa de correios - Cadastro Credito - VC\Inbox", "c:\temp")
$teller=Opslaanbijlagen("Postvak - Name\Postvak IN\Test", "c:\temp\")

;===============================================================================
;
; Function Name:    Opslaanbijlagen
; Description:      Opslaan van alle bijlagen die aan de criteria voldoen
; Syntax.........:  Opslaanbijlagen("Postvak - Mijnaam\test\subtest","C:\temp" )
; Requirement(s):   AutoIt3 with COM support (post 3.1.1)
; Return Value(s):  Not used in this example
;
; Author(s):        Iq9003
; Created:          08072009
; Modified:
;
;===============================================================================
Func Opslaanbijlagen($Postbus_user, $tempdir)
    $oOApp = ObjCreate("Outlook.Application")
    $myNamespace =$oOApp.GetNamespace("MAPI")
    ; Original folder
    $myarrayold=StringSplit ( $Postbus_user, "\")
    $myOldFolder = $myNamespace.Folders($myarrayold[1])
    For $i=2 to $myarrayold[0]
        $myOldFolder=$myOldFolder.Folders($myarrayold[$i])
    next
    For $a=$myOldFolder.Items.count to 1 Step -1
        $teller=$teller+1
        $iAttachCnt = $myOldFolder.Items($a).Attachments.Count
        If $iAttachCnt > 0 Then
            For $iAttachNum = 1 to $iAttachCnt
                $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                $sFileName = $oTemp.FileName
                $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                if stringinstr($sFileName,".doc") > 0 and stringinstr($sFileName,"Brief") > 0 then
                    $oTemp.SaveAsFile ($tempdir & $teller & $sFileName )
                endif
            Next
        EndIf
    next
    return $teller
 endfunc
Link to comment
Share on other sites

  • 1 month later...

Hi,

Here is a small piece of code which I use. (Tested with outlook 2003, with the proper permissions to read the other mailbox!)

This code saves an attachement in a mail from a different mailbox (it only saves attachements with the name brief.doc)

#Include <Array.au3>    
#Include <File.au3>             

local $teller

;$teller=Opslaanbijlagen("Caixa de correios - Cadastro Credito - VC\Inbox", "c:\temp")
$teller=Opslaanbijlagen("Postvak - Name\Postvak IN\Test", "c:\temp\")

;===============================================================================
;
; Function Name:    Opslaanbijlagen
; Description:      Opslaan van alle bijlagen die aan de criteria voldoen
; Syntax.........:  Opslaanbijlagen("Postvak - Mijnaam\test\subtest","C:\temp" )
; Requirement(s):   AutoIt3 with COM support (post 3.1.1)
; Return Value(s):  Not used in this example
;
; Author(s):        Iq9003
; Created:          08072009
; Modified:
;
;===============================================================================
Func Opslaanbijlagen($Postbus_user, $tempdir)
    $oOApp = ObjCreate("Outlook.Application")
    $myNamespace =$oOApp.GetNamespace("MAPI")
    ; Original folder
    $myarrayold=StringSplit ( $Postbus_user, "\")
    $myOldFolder = $myNamespace.Folders($myarrayold[1])
    For $i=2 to $myarrayold[0]
        $myOldFolder=$myOldFolder.Folders($myarrayold[$i])
    next
    For $a=$myOldFolder.Items.count to 1 Step -1
        $teller=$teller+1
        $iAttachCnt = $myOldFolder.Items($a).Attachments.Count
        If $iAttachCnt > 0 Then
            For $iAttachNum = 1 to $iAttachCnt
                $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                $sFileName = $oTemp.FileName
                $oTemp = $myOldFolder.Items($a).Attachments.Item($iAttachNum)
                if stringinstr($sFileName,".doc") > 0 and stringinstr($sFileName,"Brief") > 0 then
                    $oTemp.SaveAsFile ($tempdir & $teller & $sFileName )
                endif
            Next
        EndIf
    next
    return $teller
 endfunc

It worked just fine! :)

(Just changed a couple of things, like the .doc and "Brief", to make compatible to mine)

Thank you very much! ;)

Edited by SeF
Link to comment
Share on other sites

  • 3 weeks later...

It's impossible to run ObjCreate("Outlook.Application") under Windows 7 (64-bit)

Can anyone help me please to solve this problem?

Thanks!

Func _OutlookOpen()
    Local $oOutlook = ObjCreate("Outlook.Application")
    If @error Or Not IsObj($oOutlook) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $oOutlook
EndFunc
Link to comment
Share on other sites

I really found this UDF usefull. I've encountered a problems and I hope someone can help me with that. The problem is that I can't find any option to add a sender when sending an e-mail (as in: this e-mail is from). I've several accounts and I don't want the e-mail to be sent from the default account, is there anyway to change this?Thanks in advanche!

Edited by Rigest
Link to comment
Share on other sites

I really found this UDF usefull. I've encountered a problems and I hope someone can help me with that. The problem is that I can't find any option to add a sender when sending an e-mail (as in: this e-mail is from). I've several accounts and I don't want the e-mail to be sent from the default account, is there anyway to change this?Thanks in advanche!

Does anyone know if this is possible? Because this UDF is perfect for what I need, but I really need to change the sender from the default one. If this isn't possible I have to work with the mouse and send commands, and that's just so much slower (and looks worse).
Link to comment
Share on other sites

It's possible - but not with the Outlook UDF.

You could use a customized version of the _OutlookSendMail function (Ex stands for extended) in combination with the Oudlook UDF:

Func _OutlookSendMailEx($oOutlook, $sFrom = "", $sTo = "", $sCc = "", $sBcc = "", $sSubject = "", $sBody = "", $sAttachments = "", $iBodyFormat = $olFormatPlain, $iImportance = $olImportanceNormal, $sWarningClick = "")
    Local $iRc = 0, $asAttachments
    If $sTo = "" And $sCc = "" And $sBcc = "" Then
        Return SetError(1, 0, 0)
    EndIf
    If $sWarningClick <> "" And FileExists($sWarningClick) = 0 Then
        Return SetError(2, 0, 0)
    Else
        Run($sWarningClick)
    EndIf
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Local $oMessage = $oOutlook.CreateItem($olMailItem)
    $oMessage.To = $sTo
    $oMessage.Cc = $sCc
    $oMessage.Bcc = $sBcc
    $oMessage.From = $sFrom     ; <== This line and parameter $sFrom is the only difference to the UDF function
    $oMessage.Subject = $sSubject
    $oMessage.Body = $sBody
    $oMessage.BodyFormat = $iBodyFormat
    $oMessage.Importance = $iImportance
    If $sAttachments <> "" Then
        $asAttachments = StringSplit($sAttachments, ";")
        For $iNumOfAttachments = 1 To $asAttachments[0]
            $oMessage.Attachments.Add($asAttachments[$iNumOfAttachments])
        Next
    EndIf
    $oMessage.Send
    $iRc = @error
    If $iRc = 0 Then
        Return 1
    Else
        Return SetError(9, 0, 0)
    EndIf
EndFunc ;==>_OutlookSendMailEx
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I had a quick look at the code. It seems to be possible to specify a different folder as second parameter to _OutlookGetMail.

Is has to have a format of \\FolderID\\StoreID.

Unfortunately I don't know how to get this information for a local store.

Maybe Wooltown can shed some light on this?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It's possible - but not with the Outlook UDF.

You could use a customized version of the _OutlookSendMail function (Ex stands for extended) in combination with the Oudlook UDF:

Func _OutlookSendMailEx($oOutlook, $sFrom = "", $sTo = "", $sCc = "", $sBcc = "", $sSubject = "", $sBody = "", $sAttachments = "", $iBodyFormat = $olFormatPlain, $iImportance = $olImportanceNormal, $sWarningClick = "")
    Local $iRc = 0, $asAttachments
    If $sTo = "" And $sCc = "" And $sBcc = "" Then
        Return SetError(1, 0, 0)
    EndIf
    If $sWarningClick <> "" And FileExists($sWarningClick) = 0 Then
        Return SetError(2, 0, 0)
    Else
        Run($sWarningClick)
    EndIf
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Local $oMessage = $oOutlook.CreateItem($olMailItem)
    $oMessage.To = $sTo
    $oMessage.Cc = $sCc
    $oMessage.Bcc = $sBcc
    $oMessage.From = $sFrom     ; <== This line and parameter $sFrom is the only difference to the UDF function
    $oMessage.Subject = $sSubject
    $oMessage.Body = $sBody
    $oMessage.BodyFormat = $iBodyFormat
    $oMessage.Importance = $iImportance
    If $sAttachments <> "" Then
        $asAttachments = StringSplit($sAttachments, ";")
        For $iNumOfAttachments = 1 To $asAttachments[0]
            $oMessage.Attachments.Add($asAttachments[$iNumOfAttachments])
        Next
    EndIf
    $oMessage.Send
    $iRc = @error
    If $iRc = 0 Then
        Return 1
    Else
        Return SetError(9, 0, 0)
    EndIf
EndFunc ;==>_OutlookSendMailEx

You are incorrect, but you've helped me on the right way. It should be: $oMessage.Sentonbehalfofname = $sFrom. Tnx anyway ;)
Link to comment
Share on other sites

I had a quick look at the code. It seems to be possible to specify a different folder as second parameter to _OutlookGetMail.

Is has to have a format of \\FolderID\\StoreID.

...

hello,

I've tried does not work.

Instead it seems that the function works well IQ9003 (Opslaanbijlagen) that does not use Outlook-UDF.

but i want to use with outlook-UDF. Can you help?

Edited by nico18n
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Hi

I find the information here really interesting. But my problem is to insert in an rtf mail an inline picture. it means not as an attachment but the picture should appears in the mail.

The second point is that i want to send some mail with some rtf. data as attachemnt but this rtf data should be attached as text not as normal attachemnt. Can anybody have an idea how i can do it .

Thank you

Link to comment
Share on other sites

Hello !

It was a long time since I updated this UDF, unfortunatelly I have very little time now.

It would have been great if there were an area somewhere in the forum (or elsewhere) where users can contribute to a UDF written.

Contribution can consist of error correction, enhancements, nice examples etc.

If the AutoIT team could do that it would have been great for the community.

Link to comment
Share on other sites

... It would have been great if there were an area somewhere in the forum (or elsewhere) where users can contribute to a UDF written.

Contribution can consist of error correction, enhancements, nice examples etc. ...

D'accord!

That's what I have done with the Active Directory UDF. After contacting the owner of the UDF I started to enhance the UDF with help files, examples, extended error checking and some new functions.

It would be great if we could do that for other UDFs as well!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

... where users can contribute to a UDF written.

Contribution can consist of error correction, enhancements, nice examples etc. ...

If you like I can have a look at your UDF and create a list of things I can start working on.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...