Hello, Thank you Shajul for this wonderful script, this script has made my life so much easier 
and im running a little trouble and hoping some direction on how to manage this
so this is what im trying to achieve
Window A running > send hotkey > takes screenshot > send email + latest screenshot
i have no problem when using full path as the attachment address, email + attachment is sent successfully, but with this i cannot send the latest screenshot
so then this is what i have tried
ive added a Loop File/Folder on top of the Script
checking with MsgBox confirms that the file path and the latest screenshot is created correctly
Loop, C:\Users\xxx\Documents\SomeRandomProgram\Screenshots\*.png
{
If (A_LoopFileTimeCreated>Rec)
{
FPath=%A_LoopFileFullPath%
Rec=%A_LoopFileTimeCreated%
}
}
msgbox, %FPath%
and the using the file path generated from %FPath%
i add that into the script
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """John Doe"" <[email protected]>"
pmsg.To := "[email protected]"
pmsg.BCC := ""
pmsg.CC := ""
pmsg.Subject := "Subject"
;You can use either Text or HTML body like
pmsg.TextBody := "BodyMessage"
;OR
;pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><h2>Hello</h2><p>Testing!</p></body></html>"
sAttach := "%FPath%" ; this is where i add the file path
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "[email protected]"
fields.sendpassword := "MyPassword"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()
and this is the Error ive got

Hopefully someone can help and shed some light for me, thank you for anyone reading this
ps: im sorry for the bad english

edit :
this is the whole script
F3::
controlsend,, {F2}, SomeRandomProgramWindow
Loop, C:\Users\xxx\Documents\SomeRandomProgram\Screenshots\*.png
{
If (A_LoopFileTimeCreated>Rec)
{
FPath=%A_LoopFileFullPath%
Rec=%A_LoopFileTimeCreated%
}
}
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """John Doe"" <[email protected]>"
pmsg.To := "[email protected]"
pmsg.BCC := ""
pmsg.CC := ""
pmsg.Subject := "Subject"
;You can use either Text or HTML body like
pmsg.TextBody := "BodyMessage"
;OR
;pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><h2>Hello</h2><p>Testing!</p></body></html>"
sAttach := "%FPath%" ; can add multiple attachments, the delimiter is |
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "[email protected]"
fields.sendpassword := "MyPassword"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()