Attaching file to Outlook email
-
- Posts: 15
- Joined: Sep 4th, ’21, 23:26
I get the error: Cannot find the file. Verify the path and name for line
oOutlookMsg.Attachments.Add(FilePath)
The script runs ok if I comment out the Attachment.
The file 0 AR Aug 2021.xlsx is on the Desktop
The MsgBox shows the following c:\Uses\JC\OneDrive\Desktop/ 0 AR Aug 2021.xlsx
^q::
FilePath:= A_Desktop "0 AR Aug 20-21.xlsx"
msgbox,%filepath%
Ifexist,%filepath%
Run,%filepath%
;else
oOutlook:= ComObjCreate("Outlook.Application")
oOutlookMsg:= oOutlook.CreateItem(0)
oOutlookMsg.Subject:= "Testing"
oOutlookMsg.Body:= "The file in body is"
oOutlookMsg.To:="jc@ecallontario.com"
oOutlookMsg.Attachments.Add(FilePath)
oOutlookMsg.Display
oOutlookMsg.Attachments.Add(FilePath)
The script runs ok if I comment out the Attachment.
The file 0 AR Aug 2021.xlsx is on the Desktop
The MsgBox shows the following c:\Uses\JC\OneDrive\Desktop/ 0 AR Aug 2021.xlsx
^q::
FilePath:= A_Desktop "0 AR Aug 20-21.xlsx"
msgbox,%filepath%
Ifexist,%filepath%
Run,%filepath%
;else
oOutlook:= ComObjCreate("Outlook.Application")
oOutlookMsg:= oOutlook.CreateItem(0)
oOutlookMsg.Subject:= "Testing"
oOutlookMsg.Body:= "The file in body is"
oOutlookMsg.To:="jc@ecallontario.com"
oOutlookMsg.Attachments.Add(FilePath)
oOutlookMsg.Display
Example
Code: Select all
FilePath:= A_Desktop "\myfile.txt"
if not FileExist(FilePath)
msgbox % FilePath "`nDOES NOT EXIST"
else
{
oOutlook:=ComObjCreate("Outlook.Application").CreateItem(0)
oOutlook.Subject:="Attachment"
oOutlook.To:="mail@gmail.com"
oOutlook.Body:="Please find attached..."
oOutlook.Attachments.Add(FilePath)
oOutlook.Display
}
return
-
- Posts: 15
- Joined: Sep 4th, ’21, 23:26
Thanks
How would you change the script to attach a file and send info in the body for an existing email that is open. i.e. Replying to an email.
How would you change the script to attach a file and send info in the body for an existing email that is open. i.e. Replying to an email.
-
- Posts: 15
- Joined: Sep 4th, ’21, 23:26
How would I change this script if I do not want to create a new email but attach a file and enter info in the body of an existing email?
Thanks
FilePath:= A_Desktop "\myfile.txt"
if not FileExist(FilePath)
msgbox % FilePath "`nDOES NOT EXIST"
else
{
oOutlook:=ComObjCreate("Outlook.Application").CreateItem(0)
oOutlook.Subject:="Attachment"
oOutlook.To:="mail@gmail.com"
oOutlook.Body:="Please find attached..."
oOutlook.Attachments.Add(FilePath)
oOutlook.Display
}
return
Thanks
FilePath:= A_Desktop "\myfile.txt"
if not FileExist(FilePath)
msgbox % FilePath "`nDOES NOT EXIST"
else
{
oOutlook:=ComObjCreate("Outlook.Application").CreateItem(0)
oOutlook.Subject:="Attachment"
oOutlook.To:="mail@gmail.com"
oOutlook.Body:="Please find attached..."
oOutlook.Attachments.Add(FilePath)
oOutlook.Display
}
return
-
- Posts: 15
- Joined: Sep 4th, ’21, 23:26
These two files are in the same folder. I got the path from properties so they should be correct. The Excel files attaches OK but the Word file gives me an error "Cannot find file. Make sure the path and file name are correct" I get same error if I try to attach a pdf file. Any suggestions?
oOutlookMsg.Attachments.Add("C:\Users\JC\OneDrive - Ecall Ontario\2 Customers\AR\0 AR Aug 20-21.xlsx")
oOutlookMsg.Attachments.Add("C:\Users\JC\OneDrive - Ecall Ontario\2 Customers\AR\1 Wireless Call Bells direct to Pagers Jan 28-20.docx")
oOutlookMsg.Attachments.Add("C:\Users\JC\OneDrive - Ecall Ontario\2 Customers\AR\0 AR Aug 20-21.xlsx")
oOutlookMsg.Attachments.Add("C:\Users\JC\OneDrive - Ecall Ontario\2 Customers\AR\1 Wireless Call Bells direct to Pagers Jan 28-20.docx")
You need to check the file location - make sure you copy the exact file path.