Page 1 of 1

Attaching file to Outlook email

Posted: Sep 14th, ’21, 15:16
by jcfastkeys
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:="[email protected]"
oOutlookMsg.Attachments.Add(FilePath)
oOutlookMsg.Display

Re: Attaching file to Outlook email

Posted: Sep 14th, ’21, 18:38
by Marko
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:="[email protected]"
	oOutlook.Body:="Please find attached..."
	oOutlook.Attachments.Add(FilePath)
	oOutlook.Display
}
return

Attaching file to Outlook email that is open

Posted: Sep 14th, ’21, 23:00
by jcfastkeys
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.

Attaching file and info in body of anopened email. i.e. Replying to email

Posted: Sep 15th, ’21, 00:02
by jcfastkeys
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:="[email protected]"
oOutlook.Body:="Please find attached..."
oOutlook.Attachments.Add(FilePath)
oOutlook.Display
}
return

Difficulting attaching word files

Posted: Sep 16th, ’21, 16:57
by jcfastkeys
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")

Re: Problems attaching file to Outlook email

Posted: Sep 21st, ’21, 17:09
by Marko
You need to check the file location - make sure you copy the exact file path.

Re: Attaching file to Outlook email

Posted: Nov 26th, ’23, 20:57
by BarTeek
Hi,
Requesting exact instructions on what script to use to automatically add an attachment when replying to an email. (This is not about adding an attachment when creating a new message)