Problem: I have made a script that sends a mail through ComObject and it works like a charm when i use it as user, but not if i execute it with Task Scheduler.
What have i done? I have changed ComObjActive to ComObjCreate.
Code:
The body is correct and contains HTML text.
Myself = %AUMailAdress%
Recipient := Myself
Subject := Oi
Body := Ci
Recipient5 = Hidden@gmail.com
DocumentLocation = %SourceDir%\Tooloutput\AutoProjectsLog\Faults
olMailItem := 0
MailItem := ComObjCreate("Outlook.Application").CreateItem(olMailItem)
olFormatHTML := 2
MailItem.BodyFormat := olFormatHTML
MailItem.Subject := Subject
MailItem.HTMLBody := Body
Recipient := MailItem.Recipients.Add(Recipient)
Recipient.Type := 1
Loop, %DocumentLocation%\*.*
MailItem.Attachments.Add(A_LoopFileLongPath)
MailItem.cc := Recipient5
MailItem.Send
ExitApp
return
Issue: The following error i get when it tries to make a ComObject.
Error: 0x80080005 - Server execution failed
Line: #
---> 674: MailItem: = ComObjCreate ("Outlook.Application"). CreateItem (olMailItem)
Continuous running the script?
I just struggled with this about 3 hours, trying many things, including this method:
At the end, I just ran Outlook as administrator and all started working properly, using this code:
outlookApp := ComObjCreate("Outlook.Application")
MailItem := outlookApp.CreateItem(0)
MailItem.Display
System: Windows 10 x64
Outlook 2019
AHK 1.1.33.02 ran as administrator