AutoHotkey Community

It is currently May 27th, 2012, 10:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: July 18th, 2007, 8:29 pm 
Offline

Joined: October 19th, 2006, 8:22 pm
Posts: 32
Location: mo
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



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 3:16 pm 
Note: with continuation sections, you can avoid putting `n everywhere, which is neither practical nor readable.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 6:57 pm 
Note: Thats not a continuing section, its a line that is wrapping.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 6:59 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
then it should be made into a continuation section.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 7:28 pm 
Im not a vb programmer. lol.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 7:38 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Example

Code:
FileAppend,
(LTrim ` Join`s
%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
), %TEMPFILE%

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 7:45 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
Code:
FileAppend,
(LTrim
%file%objmessage.to = "%To%"
objmessage.subject = "%Subject%"
objmessage.htmlbody = "%Body%"
objmessage.configuration.fields.item
  ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objmessage.configuration.fields.item
  ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "%Smtp%"
objmessage.configuration.fields.item
  ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objmessage.configuration.fields.update
objmessage.send
), %TEMPFILE%


why the ` option? it prevents `n from working.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 8:04 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
I guess the VBS code needs those... dunno.

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2007, 7:15 pm 
Offline

Joined: September 16th, 2006, 5:34 am
Posts: 27
How do you go about specifying the SMTP server and its login and password?
D.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: XX0 and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group