Jump to content

Outlook UDF


Wooltown
 Share

Recommended Posts

Hi

Probably won't have a chance to play with this for a couple of weeks but wanted to let you know about this information. I have developed some indepth macros within outlook using VBA. There is a legitimate way to get by the security warning without resorting to automatically clicking the messagebox closed. This is a really dangerous thing to do because of the number of email viruses out there. As mentioned don't have time to work on this but here is the VBA which should be easy to translate. The trick is to use the getitemfromID method. This does not trigger the warning.

'work on selected items

Set myOlExp = myOLApp.ActiveExplorer

Set myolsel = myOlExp.Selection

'for all items do...

For Each myitem2 In myolsel

' This line will bypass the outlook security alert!!! It's a godsent!

Set myItem = Application.Session.GetItemFromID(myitem2.EntryID)

Link to comment
Share on other sites

  • 2 weeks later...

Can someone please help with this bit on script?

#include <File.au3>
#include <Date.au3>
#include "CustomMsgBox.au3"
#Include <Array.au3>
#Include <Outlook.au3>
$oOutlook = _OutlookOpen()
Opt("TrayIconDebug", 1);0=no info, 1=debug line info
Opt("WinWaitDelay", 550);250 milliseconds

$month = _DateMonthOfYear(@MON, 0)
$a = 200
$file1 = "Product Changes Report"
$dir1 = "Z:\OPERATIONS\EOD REPORTS\"
$dir2 = "Z:\OPERATIONS\PRICE FILES\PRODUCT CHANGES\" & @YEAR &"\" & $month & "\"
$today = @MDAY & "-" & @MON & "-" & @YEAR


more stuff


_OutlookSendMail($oOutlook, "Test","","", "Product Changes", "Here is todays product changes",$dir2 & "Product Changes Report-" & $today & ".pdf;" & $dir2 & "Price Changes Report-" & $today & ".pdf",$olFormatHTML,"")

it doesn't send the attachments, but when i rid of the

$dir2 & "Product Changes Report-" & $today & ".pdf;" & $dir2 & "Price Changes Report-" & $today & ".pdf"

and put the full path in for both files, it works. please help!

edit...

DOH!! in my effort to get the script working before running End Of Day, i hadn't created todays version of the file OOPPSS

Edited by happy2help
Link to comment
Share on other sites

Hi Woltdown, thanks a lot for your effort.

I have one dummy question though. When I put the body of my message like html instead of the message show up correctly it shows the html code.

I have copied Outlook.au3 to includes folder :D

#Include "Outlook.au3"
$oOutlook = _OutlookOpen()
_OutlookSendMail($oOutlook, "to@address.com","cc@address.com","", "Subject", "<html><body><b>test</b></body></html>","",$olFormatHTML)

So instead of showing a test word in bold format it shows the whole html code.

1. Do you have any idea how to work around this?

2. Also, is it possible to create the message and show it so I can have a last check/edit before sending?

Thanks in advance,

Link to comment
Share on other sites

Hi Woltdown, thanks a lot for your effort.

I have one dummy question though. When I put the body of my message like html instead of the message show up correctly it shows the html code.

I have copied Outlook.au3 to includes folder ^_^

#Include "Outlook.au3"
$oOutlook = _OutlookOpen()
_OutlookSendMail($oOutlook, "to@address.com","cc@address.com","", "Subject", "<html><body><b>test</b></body></html>","",$olFormatHTML)

So instead of showing a test word in bold format it shows the whole html code.

1. Do you have any idea how to work around this?

2. Also, is it possible to create the message and show it so I can have a last check/edit before sending?

Thanks in advance,

Just write the text as normal, and the mail will be in HTML format, how to make more formatting I don't know at the moment.

Link to comment
Share on other sites

Fantastic piece of work.

Is it possible to code the Outlook Send/Receive function? and is it also possible to code around Outlook Security rather than having to install the MAPILab Software? Ant..

I really don't know, I can look at it when I have time for it !

Link to comment
Share on other sites

Another question: Is there any way to set the 'UnRead' flag to false after processing an email?

I want to process a number of unread emails in a folder, marking them read after I process them.

I will add it as an option in _OutlookGetMail(), it should be quite easy.

Link to comment
Share on other sites

I will add it as an option in _OutlookGetMail(), it should be quite easy.

I have an OutLook folder at the same level as \Inbox. How do I search that folder using _OutlookGetMail? I can't seem to figure out how to reference it since it is not a subfolder to \Inbox.

Link to comment
Share on other sites

I have an OutLook folder at the same level as \Inbox. How do I search that folder using _OutlookGetMail? I can't seem to figure out how to reference it since it is not a subfolder to \Inbox.

There is a way to access the "root folder" in outlook, I don't remember how, but I will look at it and get back to you

Link to comment
Share on other sites

;===============================================================================
;
; Function Name:    _OutlookGetMail()
; Description:    Get all email using Microsoft Outlook.
; Syntax.........:  _OutlookGetMail($oOutlook, $sFolder = $olFolderInbox, $fSubFolder = False, $sFrom = "", $sTo = "", $sCc = "", $sBCc = "", $sSubject = "", $iImportance = "", $fOnlyReturnUnread = False, $sWarningClick = "")
; Parameter(s):  $oOutlook          - Outlook object opened by a preceding call to _OutlookOpen()
;                  $sFolder         - Optional: Folder, default = $olFolderInbox, add subfolders if wish to start search at a lower level, ex: $olFolderInbox & "\Archive"
;                                                   If you wish to access the root, use "\", Sent Items, write "\Sent Items"
;                  $fSubFolders         - Optional: Search subfolders, default = False
;                  $sFrom               - Optional: The e-mail address of the sender
;                  $sTo             - Optional: The recipiant(s)
;                  $sCc             - Optional: The CC recipiant(s) of the mail
;                  $sBCc                - Optional: The BCC recipiant(s) of the mail
;                   $sSubject             - Optional: The Subject of the mail
;                  $iImportance         - Optional: The Importance of the mail
;                   $fOnlyReturnUnread  - Optional: Default = False, set to True if you only wish the unread.
;                   $sWarningClick      - Optional: The Entire SearchString to 'OutlookWarning2.exe', Default = None
; Requirement(s):   AutoIt3 with COM support (post 3.1.1)
; Return Value(s):  On Success      - Array in the following format: [10000][16]
;                                     [0][0] - Total Number of items
;                                     [0][1] - Number of unread items
;                                     [1][0] - Sender name
;                                     [1][1] - Sender Email address
;                                     [1][2] - To
;                                     [1][3] - Cc
;                                     [1][4] - Bcc
;                                     [1][5] - ReceivedTime
;                                     [1][6] - SentOn
;                                     [1][7] - Subject
;                                     [1][8] - Folder
;                                     [1][9] - Body
;                                     [1][10] - BodyFormat
;                                     [1][11] - Importance
;                                     [1][12] - Unread
;                                     [1][13] - Size
;                                     [1][14] - FlagIcon
;                                     [1][15] - Attachments
;                                     [1][16] - Class - $olMail, $olMeetingRequest Or $olTaskRequest
;                                     [n][n] - Item n
;                  On Failure       - Returns 0 and sets @ERROR > 0
;                   @ERROR = 1      - Illegal parameters 
;                   @ERROR = 2      - OutlookWarning2.exe not found.
;                   @ERROR = 3      - No Mail found/Folder not found.
;                   @ERROR = 4      - More than 9999 Mail, the first 9999 mail will be returned
;                   @ERROR = 5      - Mailfolder not found
;                   @ERROR = 9      - ObjEvent error.
; Author(s):        Wooltown
; Created:        2009-02-25       
; Modified:      2009-03-02
;                   2009-03-10      - If folder not found, an error occured
;
;===============================================================================
Func _OutlookGetMail($oOutlook, $sFolder = $olFolderInbox, $fSubFolders = False, $sFrom = "", $sTo = "", $sCc = "", $sBCc = "", $sSubject = "", $iImportance = "", $fOnlyReturnUnread = False, $sWarningClick = "")
    If $sWarningClick <> "" And FileExists($sWarningClick) = 0 Then
        Return SetError(2, 0, 0)
    Else
        Run($sWarningClick)
    EndIf
    Local $fRoot = False
    If StringLeft($sFolder,1) = "\" Then 
        $fRoot = True
        $sFolder = StringMid($sFolder,2)
    EndIf
    If $iImportance < 0 Or $iImportance > 2 Then Return SetError(1, 0, 0)
    Local $asMail[10000][17], $iRc = 0, $iFolderFound = 1
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    Local $oNamespace = $oOutlook.GetNamespace("MAPI")
    If StringRight($sFolder,1) = "\" Then $sFolder = StringLeft($sFolder,StringLen($sFolder) - 1)
    Local $sSubFolderParts = StringSplit ( $sFolder, "\")
    If $fRoot = True Then 
        $sSubFolderParts[0] = 0
        Local $oInbox = $oNamespace.GetDefaultFolder($olFolderInbox)
        If $sFolder = "" Then 
            Local $oFolder = $oInbox.Parent
        Else
            Local $sFolderName = $oInbox.Parent
            For $idx = 1 To $sFolderName.Folders.Count
                If $sFolderName.Folders.Item($idx).Name = $sFolder Then Local $oFolder = $sFolderName.Folders.Item($idx)
            Next
        EndIf
    Else
        Local $oFolder = $oNamespace.GetDefaultFolder($sSubFolderParts[1])
    EndIf
    If IsObj($oFolder) = 0 Then Return SetError(5, 0, 0)
    Local $sRootFolderName = $oFolder.Name
    $asMail[0][0] = 0
    $asMail[0][1] = 0
    If $sSubFolderParts[0] > 1  Then
        $iFolderFound = _OutlookFindRootFolder($oFolder,$sRootFolderName,StringMid($sFolder,StringInStr($sFolder,"\")+ 1))
    EndIf
    If $iFolderFound = 0 Then Return SetError(5, 0, 0)
    _OutlookFindMailInTree($asMail, $oFolder, $sRootFolderName, $fSubFolders, $sFrom, $sTo, $sCc, $sBCc, $sSubject, $iImportance, $fOnlyReturnUnread)
    $iRc = @ERROR
    If $iRc = 4 Then SetError (4)
    If $asMail[0][0] = 0 Then Return SetError(3, 0, 0)
    Redim $asMail[$asMail[0][0] + 1][17]
    _ArraySort($asMail,1,1,0,5)
    Return $asMail
EndFunc

Updated _OutlookGetMail()

Use "\" to access the root folder, use "\Sent Items" for your sent Items and so on.

I will store it in the main zip.file, will just add some extra features first, Mark as "Read/Unread" fo example.

I think of add it as an option to _OutlookGetMail(), set Status to "Read/Unread", other ideas are welcome.

Link to comment
Share on other sites

New options in _OutlookGetMail() & _OutlookSaveMail(), ability to access "Root folder" and change read/unread status

Have searched for the ability to simulate send/receive button, but no success.

In Tools|Options|Mail Setup|Send/Receive|Send/Receive you can setup automatic Send and Receives including Send and Receive on Exit I guess the question is how to trigger this time interval and event driven Outlook function. Thinking outside the box perhaps you simply make active the Send/Receive option on Exit and have the AutoIT routine simply Open/Close/Open Outlook to perform the Send/Receive which will work but unfortunately is not an elegant solution. Ant..

Link to comment
Share on other sites

Hi

I looked into the application get id method I referred to earlier as a way to get by the security prompt. Seems like it can only be done in VBA, that's really too bad. Another option is to use redemption, it's not a solution for me, but anyone interested just google outlook + redemption. Below is the code I was playing with. As expected the subject and number of messages don't trigger security prompt. The security was put in to stop viruses from sending itself to your addressbook.

#include <StaticConstants.au3>
HotKeySet("{esc}", "Terminate")
GUICreate("outlook Info Summary", 600,300,-1,-1)
$unread=GUICtrlCreateLabel("",5,5,20,20,$SS_right)
$unread2=GUICtrlCreateLabel("",25,3,100,30,$SS_LEFT)
$details2=GUICtrlCreateLabel("",110,-15,460,290,$SS_LEFT)
newmessages()
GUISetState()
While 1
sleep(200)
WEnd

Func newmessages()
$strsubject=""
$otl = ObjCreate("Outlook.Application")
$session = $otl.GetNameSpace("MAPI")
$inbox = $session.GetDefaultFolder(6)
$c=0
For $m In $inbox.items
If $m.unread Then
    $c = $c + 1
    ;$myItem = application.session.GetItemFromID($m.EntryID)
    ;MsgBox(0,"",$myItem)
; $strItemName = $myItem.SenderName
     $strsubject= $strsubject&@CR&$m.Subject
EndIf
Next
$session.logoff
$s = "s"
If $c = 1 Then $s = ""
GUICtrlSetFont($unread,15,"Franklin Gothic Medium")
GUICtrlSetData($unread,$c)
GUICtrlSetFont($unread2,8,"Franklin Gothic Medium")
GUICtrlSetData($unread2," unread" &@CR&" message" & $s)
GUICtrlSetFont($details2,11,"Arial")
GUICtrlSetData($details2,$strsubject)

EndFunc

func terminate()
Exit 0
EndFunc
Link to comment
Share on other sites

Updated _OutlookGetMail()

Use "\" to access the root folder, use "\Sent Items" for your sent Items and so on.

I will store it in the main zip.file, will just add some extra features first, Mark as "Read/Unread" fo example.

I think of add it as an option to _OutlookGetMail(), set Status to "Read/Unread", other ideas are welcome.

Wooltown, thanks for making these changes!

Edited by Capel
Link to comment
Share on other sites

I'm getting some unexpected results and not sure if it is a bug or something I'm not doing. So, I have an OL folder that received email from a web page. The body of the email contains a single string of characters with no CRLF. The example below shoud just be one line but this forum s/w keeps breaking it into two!

Adam|Smith|smith1820@comcast.net|a28015|True|True|True|2|4|False|False|False|False|False|Select|Sele

ct|Select|SM|0

When I process this with Outlook.au3 I get the following string. The first part of the string is repeated and a CRLF is inserted.

Adam|Smith|smith1820@comcast.net|a28015|True|True|True|2|4|False|False|F
Adam|Smith|alse|False|False|Select|Select|Select|SM|0|

I have no idea why AutoIT is doing this. Help!

Edited by Capel
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...