VBS question: Get Outlook item property?
Posted: Mon Apr 06, 2020 6:03 pm
I might be "biting off more than I can chew" with this project, but I'd like to determine the sender of an email. I guess this is probably possible with VBScript(??)
I'm using an installed version of Outlook. It is Outlook Version 1920 and it syncs with an Exchange Server at the public school I work at. I'm using a laptop with Windows 10, 64bit.
A hotkey is assigned to the RoboTask task, and it will be activated only when Outlook is running and there is an email that is already opened and selected. I want RoboTask to determine the email address of the sender and save it to a variable.
I looked around online and found this: http://vbcity.com/forums/t/36217.aspx
You can see the log below. Is says there's a closed parenth missing ")" at line 1, but that doesn't seem correct(?)
Also, the website says
Also, I have no idea if I'm even using this code correctly as a step in my Task...
Is it even possible to do what I'm attempting?
I'm using an installed version of Outlook. It is Outlook Version 1920 and it syncs with an Exchange Server at the public school I work at. I'm using a laptop with Windows 10, 64bit.
A hotkey is assigned to the RoboTask task, and it will be activated only when Outlook is running and there is an email that is already opened and selected. I want RoboTask to determine the email address of the sender and save it to a variable.
I looked around online and found this: http://vbcity.com/forums/t/36217.aspx
You can see the log below. Is says there's a closed parenth missing ")" at line 1, but that doesn't seem correct(?)
Also, the website says
I do see that my computer has a file, "/System32/cdosys.dll." But I don't know it that's what they're referring to.You will need to add a reference to "Microsoft CDO x.xx Library" (cdo.dll)
Also, I have no idea if I'm even using this code correctly as a step in my Task...
Is it even possible to do what I'm attempting?
I: 4/6/2020 9:36:26 AM: ****** Starting task: GetEmailSender ******************
I: 4/6/2020 9:36:26 AM: Executing "1.VB Script"
E: 4/6/2020 9:36:26 AM: Error: Line number 1 (28), Expected ')'
E: 4/6/2020 9:36:26 AM: An error occurred. Step #1 (VB Script).
E: 4/6/2020 9:36:26 AM: Task execution is aborted
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|327331060
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task9"
Hide=INTEGER|0
ID=INTEGER|1823632352
LogOnAsUser=INTEGER|1
Name=STRING|"GetEmailSender"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
[Actions\Action1]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//This will be triggered when an Outlook email item is selected."
Params=FOLDER
[Actions\Action1\Params]
comment=STRING|"This will be triggered when an Outlook email item is selected."
[Actions\Action2]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//It is meant to get the email address of the person that sent the selected email."
Params=FOLDER
[Actions\Action2\Params]
comment=STRING|"It is meant to get the email address of the person that sent the selected email."
[Actions\Action3]
ActionID=STRING|"A_SCRIPT_VBSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"VB Script"
Params=FOLDER
[Actions\Action3\Params]
expandvars=STRING|"0"
line00000000=STRING|"Function GetSenderID(objMsg As Outlook.MailItem) As String"
line00000001=STRING|"'This function returns an email's Sender ID as someone@somewhere.com"
line00000002=STRING|"'http://vbcity.com/forums/t/36217.aspx"
line00000004=STRING|"On Error GoTo ErrHndlr"
line00000006=STRING|" Dim objCDOMsg As MAPI.Message"
line00000007=STRING|" Dim objSession As MAPI.Session"
line00000008=STRING|" Dim strEntryID As String"
line00000009=STRING|" Dim strStoreID As String"
line0000000B=STRING|" Set objSession = CreateObject(""MAPI.Session"")"
line0000000C=STRING|" 'Logon to existing session."
line0000000D=STRING|" objSession.Logon """", """", False, False"
line0000000E=STRING|" ' Get message Information"
line0000000F=STRING|" strEntryID = objMsg.EntryID"
line00000010=STRING|" strStoreID = objMsg.Parent.StoreID"
line00000011=STRING|" ' Get the message"
line00000012=STRING|" Set objCDOMsg = objSession.GetMessage(strEntryID, strStoreID)"
line00000013=STRING|" ' Extract the Sender's Address and Return value"
line00000014=STRING|" GetSenderID = objCDOMsg.Sender.Address"
line00000016=STRING|" ' Clean Up"
line00000017=STRING|" Set objCDOMsg = Nothing"
line00000018=STRING|" objSession.Logoff"
line00000019=STRING|" Set objSession = Nothing"
line0000001A=STRING|" Exit Function"
line0000001C=STRING|"ErrHndlr:"
line0000001D=STRING|" MsgBox Err.Description"
line0000001F=STRING|"End Function"
linecount=STRING|"32"
savescript=STRING|"0"
[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Var = {GetSenderID}"""
Params=FOLDER
[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"Var = {GetSenderID}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Events]
Event1=FOLDER
[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_HOTKEY"
Name=STRING|"Shift+Ctrl+Alt+G"
Params=FOLDER
UniqueID=INTEGER|-1020884040
[Events\Event1\Params]
hotkey=STRING|"57415"