AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Send a attachment without any dll calls.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
xXJa50nXx



Joined: 19 Oct 2006
Posts: 32
Location: mo

PostPosted: Wed Jul 18, 2007 8:29 pm    Post subject: Send a attachment without any dll calls. Reply with quote

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

Back to top
View user's profile Send private message Send e-mail
Helpy
Guest





PostPosted: Thu Jul 19, 2007 3:16 pm    Post subject: Reply with quote

Note: with continuation sections, you can avoid putting `n everywhere, which is neither practical nor readable.
Back to top
xXja50nXx as a guest
Guest





PostPosted: Thu Jul 19, 2007 6:57 pm    Post subject: Reply with quote

Note: Thats not a continuing section, its a line that is wrapping.
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jul 19, 2007 6:59 pm    Post subject: Reply with quote

then it should be made into a continuation section.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
xXja50nXx as a guest
Guest





PostPosted: Thu Jul 19, 2007 7:28 pm    Post subject: Reply with quote

Im not a vb programmer. lol.
Back to top
daonlyfreez



Joined: 16 Mar 2005
Posts: 745
Location: Berlin

PostPosted: Thu Jul 19, 2007 7:38 pm    Post subject: Reply with quote

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%

_________________
(sorry, homesite offline atm)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jul 19, 2007 7:45 pm    Post subject: Reply with quote

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.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
daonlyfreez



Joined: 16 Mar 2005
Posts: 745
Location: Berlin

PostPosted: Thu Jul 19, 2007 8:04 pm    Post subject: Reply with quote

I guess the VBS code needs those... dunno.
_________________
(sorry, homesite offline atm)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
djeaton3162



Joined: 16 Sep 2006
Posts: 23

PostPosted: Thu Sep 20, 2007 7:15 pm    Post subject: Reply with quote

How do you go about specifying the SMTP server and its login and password?
D.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group