Jump to content

Recommended Posts

Posted

Using the Outlook UDF I am trying to automate sending a .oft template that contains an attachment and message etc to new hires within the company.

I am not getting any errors when running the script but when trying to execute the program, nothing appears to be happening. Not sure what I am missing.

 

 

#include-once
#Include <Date.au3>
#Include <Array.au3>
; #INDEX# =======================================================================================================================
; Title .........:  Outlook
; AutoIt Version:   3.3.0
; Language:         English
; Description ...:  Functions that assist with MS Outlook
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_OutlookOpen
;_OutlookSendMail
;_OutlookGetMail
;_OutlookSaveMail
;_OutlookDeleteMail
;_OutlookCopyMail - Not started
;_OutlookMoveMail - Not started
;_OutlookCreateNote
;_OutlookGetNotes
;_OutlookDeleteNote
;_OutlookModifyNote
;_OutlookCreateTask
;_OutlookGetTasks
;_OutlookDeleteTask
;_OutlookModifyTask
;_OutlookCreateAppointment
;_OutlookGetAppointments
;_OutlookModifyAppointment - Modify single appointment in a recurring appointment doesn't work.
;_OutlookDeleteAppointment - Not started
;_OutlookCreateContact
;_OutlookGetContacts
;_OutlookModifyContact - Not started
;_OutlookDeleteContact - Not started
;_OutlookCreateDistList
;_OutlookGetDistLists
;_OutlookDeleteDistList
;_OutlookDeleteDistListMember
;_OutlookModifyDistList - Not working
;_OutlookFolderExist
;_OutlookFolderAdd
;_OutlookFolderDelete
;_OutlookError
; ===============================================================================================================================

const $olForward=2
const $olReply=0
const $olReplyAll=1
const $olReplyFolder=3
const $olRespond=4
const $olEmbedOriginalItem=1
const $olIncludeOriginalText=2
const $olIndentOriginalText=3
const $olLinkOriginalItem=4
const $olOmitOriginalText=0
const $olReplyTickOriginalText=1000
const $olUserPreference=5
const $olOpen=0
const $olPrompt=2
const $olSend=1
const $olDontShow=0
const $olMenu=1
const $olMenuAndToolbar=2
const $olByReference=4
const $olByValue=1
const $olEmbeddeditem=5
const $olOLE=6
const $olFormatHTML=2
const $olFormatPlain=1
const $olFormatRichText=3
const $olFormatUnspecified=0
const $olBusy=2
const $olFree=0
const $olOutOfOffice=3
const $olTentative=1
const $olLowBandwidth=200
const $olFriday=32
const $olMonday=2
const $olSaturday=64
const $olSunday=1
const $olThursday=16
const $olTuesday=4
const $olWednesday=8
const $olFolderCalendar=9
const $olFolderContacts=10
const $olFolderDeletedItems=3
const $olFolderDrafts=16
const $olFolderInbox=6
const $olFolderJournal=11
const $olFolderJunk=23
const $olFolderNotes=12
const $olFolderOutbox=4
const $olFolderSentMail=5
const $olFolderTasks=13
const $olPublicFoldersAllPublicFolders=18
const $olFolderConflicts=19
const $olFolderLocalFailures=21
const $olFolderServerFailures=22
const $olFolderSyncIssues=20
const $olAgent=3
const $olDistList=1
const $olForum=2
const $olOrganization=4
const $olPrivateDistList=5
const $olRemoteUser=6
const $olUser=0
const $olFullItem=1
const $olHeaderOnly=0
const $olEditorHTML=2
const $olEditorRTF=3
const $olEditorText=1
const $olEditorWord=4
const $olCachedConnectedDrizzle=600
const $olCachedConnectedFull=700
const $olCachedConnectedHeaders=500
const $olCachedDisconnected=400
const $olCachedOffline=200
const $olDisconnected=300
const $olNoExchange=0
const $olOffline=100
const $olOnline=800
const $olBlueFlagIcon=5
const $olGreenFlagIcon=3
const $olNoFlagIcon=0
const $olOrangeFlagIcon=2
const $olPurpleFlagIcon=1
const $olRedFlagIcon=6
const $olYellowFlagIcon=4
const $olFlagComplete=1
const $olFlagMarked=2
const $olNoFlag=0
const $olFolderDisplayFolderOnly=1
const $olFolderDisplayNoNavigation=2
const $olFolderDisplayNormal=0
const $olDefaultRegistry=0
const $olFolderRegistry=3
const $olOrganizationRegistry=4
const $olPersonalRegistry=2
const $olFemale=1
const $olMale=2
const $olUnspecified=0
const $olImportanceHigh=2
const $olImportanceLow=0
const $olImportanceNormal=1
const $olDiscard=1
const $olPromptForSave=2
const $olSave=0
const $olAppointmentItem=1
const $olContactItem=2
const $olDistributionListItem=7
const $olJournalItem=4
const $olMailItem=0
const $olNoteItem=5
const $olPostItem=6
const $olTaskItem=3
const $olAssociatedContact=1
const $olBusiness=2
const $olHome=1
const $olNone=0
const $olOther=3
const $olBCC=3
const $olCC=2
const $olOriginator=0
const $olTo=1
const $olOptional=2
const $olOrganizer=0
const $olRequired=1
const $olResource=3
const $olMeetingAccepted=3
const $olMeetingDeclined=4
const $olMeetingTentative=2
const $olMeeting=1
const $olMeetingCanceled=5
const $olMeetingReceived=3
const $olNonMeeting=0
const $olExchangeConferencing=2
const $olNetMeeting=0
const $olNetShow=1
const $olBlue=0
const $olGreen=1
const $olPink=2
const $olWhite=4
const $olYellow=3
const $olAction=32
const $olActions=33
const $olAddressEntries=21
const $olAddressEntry=8
const $olAddressList=7
const $olAddressLists=20
const $olApplication=0
const $olAppointment=26
const $olAttachment=5
const $olAttachments=18
const $olConflict=117
const $olConflicts=118
const $olContact=40
const $olDistributionList=69
const $olDocument=41
const $olException=30
const $olExceptions=29
const $olExplorer=34
const $olExplorers=60
const $olFolder=2
const $olFolders=15
const $olFormDescription=37
const $olInspector=35
const $olInspectors=61
const $olItemProperties=98
const $olItemProperty=99
const $olItems=16
const $olJournal=42
const $olLink=75
const $olLinks=76
const $olMail=43
const $olMeetingCancellation=54
const $olMeetingRequest=53
const $olMeetingResponseNegative=55
const $olMeetingResponsePositive=56
const $olMeetingResponseTentative=57
const $olNamespace=1
const $olNote=44
const $olOutlookBarGroup=66
const $olOutlookBarGroups=65
const $olOutlookBarPane=63
const $olOutlookBarShortcut=68
const $olOutlookBarShortcuts=67
const $olOutlookBarStorage=64
const $olPages=36
const $olPanes=62
const $olPost=45
const $olPropertyPages=71
const $olPropertyPageSite=70
const $olRecipient=4
const $olRecipients=17
const $olRecurrencePattern=28
const $olReminder=101
const $olReminders=100
const $olRemote=47
const $olReport=46
const $olResults=78
const $olSearch=77
const $olSelection=74
const $olSyncObject=72
const $olSyncObjects=73
const $olTask=48
const $olTaskRequest=49
const $olTaskRequestAccept=51
const $olTaskRequestDecline=52
const $olTaskRequestUpdate=50
const $olUserProperties=38
const $olUserProperty=39
const $olView=80
const $olViews=79
const $olExcelWorkSheetItem=8
const $olPowerPointShowItem=10
const $olWordDocumentItem=9
const $olLargeIcon=0
const $olSmallIcon=1
const $olFolderList=2
const $olNavigationPane=4
const $olOutlookBar=1
const $olPreview=3
const $olDoNotForward=1
const $olPermissionTemplate=2
const $olUnrestricted=0
const $olUnknown=0
const $olWindows=1
const $olPassport=2
const $olApptException=3
const $olApptMaster=1
const $olApptNotRecurring=0
const $olApptOccurrence=2
const $olRecursDaily=0
const $olRecursMonthly=2
const $olRecursMonthNth=3
const $olRecursWeekly=1
const $olRecursYearly=5
const $olRecursYearNth=6
const $olMarkedForCopy=3
const $olMarkedForDelete=4
const $olMarkedForDownload=2
const $olRemoteStatusNone=0
const $olUnMarked=1
const $olResponseAccepted=3
const $olResponseDeclined=4
const $olResponseNone=0
const $olResponseNotResponded=5
const $olResponseOrganized=1
const $olResponseTentative=2
const $olDoc=4
const $olHTML=5
const $olICal=8
const $olMSG=3
const $olMSGUnicode=9
const $olRTF=1
const $olTemplate=2
const $olTXT=0
const $olVCal=7
const $olVCard=6
const $olConfidential=3
const $olNormal=0
const $olPersonal=1
const $olPrivate=2
const $olNoItemCount=0
const $olShowTotalItemCount=2
const $olShowUnreadItemCount=1
const $olAscending=1
const $olDescending=2
const $olSortNone=0
const $olStoreANSI=3
const $olStoreDefault=1
const $olStoreUnicode=2
const $olSyncStarted=1
const $olSyncStopped=0
const $olTaskDelegationAccepted=2
const $olTaskDelegationDeclined=3
const $olTaskDelegationUnknown=1
const $olTaskNotDelegated=0
const $olDelegatedTask=1
const $olNewTask=0
const $olOwnTask=2
const $olFinalStatus=3
const $olUpdate=2
const $olTaskAccept=2
const $olTaskAssign=1
const $olTaskDecline=3
const $olTaskSimple=0
const $olTaskComplete=2
const $olTaskDeferred=4
const $olTaskInProgress=1
const $olTaskNotStarted=0
const $olTaskWaiting=3
const $olTrackingDelivered=1
const $olTrackingNone=0
const $olTrackingNotDelivered=2
const $olTrackingNotRead=3
const $olTrackingRead=6
const $olTrackingRecallFailure=4
const $olTrackingRecallSuccess=5
const $olTrackingReplied=7
const $olCombination=19
const $olCurrency=14
const $olDateTime=5
const $olDuration=7
const $olFormula=18
const $olKeywords=11
const $olNumber=3
const $olOutlookInternal=0
const $olPercent=12
const $olText=1
const $olYesNo=6
const $olViewSaveOptionAllFoldersOfType=2
const $olViewSaveOptionThisFolderEveryone=0
const $olViewSaveOptionThisFolderOnlyMe=1
const $olCalendarView=2
const $olCardView=1
const $olIconView=3
const $olTableView=0
const $olTimelineView=4


;===============================================================================
;
; Function Name:    _OutlookSendMail()
; Description:      Send an email using Microsoft Outlook.
; Syntax.........:  _OutlookSendMail($oOutlook, $sTo = "", $sCc = "", $sBCc = "", $sSubject = "", $sBody = "", $sAttachments = "", $iBodyFormat = $olFormatUnspecified, $iImportance = $olImportanceNormal, $sWarningClick = "")
; Parameter(s):     $oOutlook       - Outlook object opened by a preceding call to _OutlookOpen()
;                   $sTo            - Optional: The recipiant(s), separated by ;
;                   $sCc            - Optional: The CC recipiant(s) of the mail, separated by ;
;                   $sBCc           - Optional: The BCC recipiant(s) of the mail, separated by ;
;                   $sSubject       - Optional: The Subject of the mail
;                   $sBody          - Optional: The Body of the mail
;                   $sAttachments   - Optional: Attachments, separated by ;
;                   $iBodyFormat    - Optional: The Bodyformat of the mail, default = $olFormatUnspecified
;                   $iImportance    - Optional: The Importance of the mail, default = $olImportanceNormal
;                   $sWarningClick  - Optional: The Entire SearchString to 'OutlookWarning1.exe', Default = None
; Requirement(s):   AutoIt3 with COM support (post 3.1.1)
; Return Value(s):  On Success      - Returns 1
;                   On Failure      - Returns 0 and sets @ERROR > 0
;                   @ERROR = 1      - No To, Cc or BCc specified.
;                   @ERROR = 2      - OutlookWarning1.exe not found.
;                   @ERROR = 9      - ObjEvent error.
; Author(s):        Wooltown
; Created:          2009-02-09
; Modified:         2009-02-24      - Several attachments didn't work
;
;===============================================================================
Func _OutlookSendMail($oOutlook, $sTo = "matt.wood2@wnco.com", $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.CreateItemFromTemplate(".\WelcomeROW.oft")
    $oMessage.To = $sTo
    $oMessage.Cc = $sCc
    $oMessage.Bcc = $sBCc
    $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

 

Posted

Two things:

  • You are using the old Outlook UDF.
    Please have a look at my signature for the new OutlookEX UDF. Function _OL_ItemCreate, _OL_ItemRecipientAdd and _OL_ItemSend are the functions you are looking for.
  • You have modified the function, but where do you call it?

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

 

  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Correct

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

 

Posted

To create a new mail based on your template you have to use _OL_ItemCreate and pass the OFT as parameter 4.

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

 

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
×
×
  • Create New...