Attaching file to Outlook email

Share your favorite FastKeys commands
Post Reply
jcfastkeys
Posts: 15
Joined: Sep 4th, ’21, 23:26

Post by jcfastkeys » Sep 14th, ’21, 15:16

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
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Sep 14th, ’21, 18:38

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
jcfastkeys
Posts: 15
Joined: Sep 4th, ’21, 23:26

Post by jcfastkeys » Sep 14th, ’21, 23:00

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.
jcfastkeys
Posts: 15
Joined: Sep 4th, ’21, 23:26

Post by jcfastkeys » Sep 15th, ’21, 00:02

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
jcfastkeys
Posts: 15
Joined: Sep 4th, ’21, 23:26

Post by jcfastkeys » Sep 16th, ’21, 16:57

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")
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Sep 21st, ’21, 17:09

You need to check the file location - make sure you copy the exact file path.
BarTeek
Posts: 1
Joined: Nov 26th, ’23, 20:49

Post by BarTeek » Nov 26th, ’23, 20:57

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)
Post Reply