This is a very simple example of how to send a attachment.
Just put the full file name in the attach variable.
Code:
attach= ;filename here.
Gui, Add, Edit,vFROM x66 y27 w100 h20
Gui, Add, Edit,vTo x66 y57 w100 h20 ,
Gui, Add, Edit,vSmtp x66 y87 w100 h20
Gui, Add, Edit,vSubject x66 y117 w100 h20
Gui, Add, Edit,vBody x66 y147 w240 h100
Gui, Add, Text, x6 y27 w60 h20 R4 , From:
Gui, Add, Text, x6 y57 w60 h20 , To:
Gui, Add, Text, x6 y87 w60 h20, SMTP:
Gui, Add, Text, x6 y117 w60 h20 , Subject:
Gui, Add, Text, x6 y147 w60 h20 , Body:
Gui, Add, button, x6 y210 , Send
Gui, Show, x207 y497 h270 w318, AHK Email
return
GuiClose:
ExitApp
ButtonSend:
Gui, Submit, NoHide
StringReplace, body, body, `n,<br> , All
TEMPFILE = %TEMP%\EMAIL.vbs
IfExist, %TEMPFILE%
FileDelete, %TEMPFILE%
FileAppend, set objmessage = createobject("cdo.message")`n objmessage.from = "%FROM%" `n objMessage.AddAttachment "%Attach%"`n objmessage.to = "%To%" `n objmessage.subject = "%Subject%" `n objmessage.htmlbody = "%Body%" `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "%Smtp%" `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 `n objmessage.configuration.fields.update `n objmessage.send ,%TEMPFILE%
RunWait, %TEMPFILE%
FileDelete, %TEMPFILE%
Return
With this code you can send as many attachments as you want.
This code will send a directory.
Code:
Gui, Add, Edit,vFROM x66 y27 w100 h20
Gui, Add, Edit,vTo x66 y57 w100 h20 ,
Gui, Add, Edit,vSmtp x66 y87 w100 h20 ,
Gui, Add, Edit,vSubject x66 y117 w100 h20
Gui, Add, Edit,vBody x66 y147 w240 h100
Gui, Add, Text, x6 y27 w60 h20 R4 , From:
Gui, Add, Text, x6 y57 w60 h20 , To:
Gui, Add, Text, x6 y87 w60 h20, SMTP:
Gui, Add, Text, x6 y117 w60 h20 , Subject:
Gui, Add, Text, x6 y147 w60 h20 , Body:
Gui, Add, button, x6 y210 , Send
Gui, Show, x207 y497 h270 w318, AHK Email
return
GuiClose:
ExitApp
ButtonSend:
Gui, Submit, NoHide
StringReplace, body, body, `n,<br> , All
TEMPFILE = %TEMP%\EMAIL.vbs
IfExist, %TEMPFILE%
FileDelete, %TEMPFILE%
file= set objmessage = createobject("cdo.message")`n objmessage.from = "%FROM%" `n
FileSelectFolder,folder
Loop, %folder%\*, , 1 ; Recurse into subfolders.
{
file=%file%objMessage.AddAttachment "%A_LoopFileFullPath%"`n
}
file=%file%objmessage.to = "%To%" `n objmessage.subject = "%Subject%" `n objmessage.htmlbody = "%Body%" `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "%Smtp%" `n objmessage.configuration.fields.item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 `n objmessage.configuration.fields.update `n objmessage.send
FileAppend, %file% ,%TEMPFILE%
RunWait, %TEMPFILE%
FileDelete, %TEMPFILE%
msgbox Sent
Return