 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
sanoopdas
Joined: 17 Oct 2008 Posts: 13 Location: KERALA
|
Posted: Mon Dec 01, 2008 12:22 pm Post subject: How can i Send mail using ahk |
|
|
I want to send mail to a an account without showing the outlook mail interface.
I have searched in ahk. But i can't able to take that links, because that are restricted in my domain.
Pls Help me fast... |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
|
| Back to top |
|
 |
peterm
Joined: 25 Jul 2006 Posts: 51
|
Posted: Mon Dec 01, 2008 7:09 pm Post subject: |
|
|
This is how I write an email from a script to send a file.
It is Outlook specific, and from my view, dirty (in that using keys to make it work is just not right)
I spent a long time playing around with this as things like Attachement do not work from a script. Beyond my knowledge as to why, but it doesn't.
This is called from a gui and I haven't made it into a function
| Code: |
; This is Outlook specfic
; Code snippet by Peterm
;
Mail_File:
; Mail message out
ShowConfirmationBox := 1
; If no file selected then return
If MyListBox =
{
MsgBox No file selected
SB_SetText("No file selected",1)
Return
}
IfNotExist, %File_Link%
{
MsgBox %File_Link%`nFile does not Exist
SB_SetText("File does not Exist",1)
Return
}
SB_SetText("Mailing the file",1)
Sleep, 50
If ErrorLevel = Error
{
MsgBox Could not open specified file. Perhaps it is does not Exist.
SB_SetText("Couldn't open the selected file",1)
Return
}
SB_SetText("Copying File to Clipboard",1)
; Load clipboard with file as this is quicker
clipboard = %File_Link%
ClipWait
SB_SetText("Opening Outlook",1)
var_subject = Drawing
var_body = %File_Link%`%0A
var_address = peter.meares@edwardsvacuum.com
; var_text = The shortcut to the file is `%0A`%0A
var_sign_off = `%0A`%0ARegards`%0APeter
;Start the mail process
RunWait mailto:%var_address%?body=%var_body%&subject=%var_subject%
; Add attachment to Outlook via key controls
; switch mouse and keys off
BlockInput On
Sleep 2000
Send {ALT}
Sleep 1000
Send i
Sleep 200
Send f
Sleep 1000
Send ^v{Enter}
Sleep 2000
Send {End}{Down}
BlockInput Off
If (ShowConfirmationBox)
{
MsgBox 4,Email Confirmation, Send email?
IfMsgBox Yes
{
Send ^{Enter}
SB_SetText("File sent",1)
}
Else
SB_SetText("File not sent",1)
}
leave_routine:
Return
|
Peterm |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Tue Dec 02, 2008 3:13 am Post subject: |
|
|
ok couple things
your either going to need to decide a mail client or learn about telnet
You can actually use telnet to send email from commandline
http://www.google.com/search?q=email+telnet&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7SUNA_en
thats a bit of a learning curve for most but its totally doable
aside from telnet your going to need to designate a mail client.
outlook
browser based
blat
etc...
then your going to need to examin automation techniques for each
outlook you will want to learn about COM or vba and use ws4ahk by eric the turtle sky is the limit here but this has a steep learning curve
blat this will probably be the easiest to learn but it requires an additional download and program
browser based email
Now we are talking versitility here
you can use cURL
COM with IE
i Macros with firefox
or one of several winhttp functions found in the forums
COM is more viersitile but offers the most complex learning curve while cURL is probably the easiest but like the blat option will require an additional program
once you have decided a method your comfortable with then you can post more specific questions _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
Posted: Tue Dec 02, 2008 11:41 am Post subject: |
|
|
| peterm wrote: | This is how I write an email from a script to send a file.
It is Outlook specific, and from my view, dirty (in that using keys to make it work is just not right)
I spent a long time playing around with this as things like Attachement do not work from a script. Beyond my knowledge as to why, but it doesn't.
This is called from a gui and I haven't made it into a function
| Code: |
; This is Outlook specfic
; Code snippet by Peterm
;
Mail_File:
; Mail message out
ShowConfirmationBox := 1
; If no file selected then return
If MyListBox =
{
MsgBox No file selected
SB_SetText("No file selected",1)
Return
}
IfNotExist, %File_Link%
{
MsgBox %File_Link%`nFile does not Exist
SB_SetText("File does not Exist",1)
Return
}
SB_SetText("Mailing the file",1)
Sleep, 50
If ErrorLevel = Error
{
MsgBox Could not open specified file. Perhaps it is does not Exist.
SB_SetText("Couldn't open the selected file",1)
Return
}
SB_SetText("Copying File to Clipboard",1)
; Load clipboard with file as this is quicker
clipboard = %File_Link%
ClipWait
SB_SetText("Opening Outlook",1)
var_subject = Drawing
var_body = %File_Link%`%0A
var_address = peter.meares@edwardsvacuum.com
; var_text = The shortcut to the file is `%0A`%0A
var_sign_off = `%0A`%0ARegards`%0APeter
;Start the mail process
RunWait mailto:%var_address%?body=%var_body%&subject=%var_subject%
; Add attachment to Outlook via key controls
; switch mouse and keys off
BlockInput On
Sleep 2000
Send {ALT}
Sleep 1000
Send i
Sleep 200
Send f
Sleep 1000
Send ^v{Enter}
Sleep 2000
Send {End}{Down}
BlockInput Off
If (ShowConfirmationBox)
{
MsgBox 4,Email Confirmation, Send email?
IfMsgBox Yes
{
Send ^{Enter}
SB_SetText("File sent",1)
}
Else
SB_SetText("File not sent",1)
}
leave_routine:
Return
|
Peterm |
This is fine if the script is for personal use only then you can set things up accordingly.
This is no way effcient for distribution thou. Go with blat or telnet. |
|
| Back to top |
|
 |
Lithodora
Joined: 02 Jul 2006 Posts: 23
|
Posted: Tue Dec 16, 2008 12:05 am Post subject: |
|
|
I have to use a .JS file to get the job done.
In my AHK code I use: | Code: | | Run %comspec% \c "Path to my JS script file" "email address of recipient" "subject line" "file path of attachment" "bodyofemail" |
Every argument is handed off in quotes to ensure spaces are delt with appropriately.
just save this as something.js
| Code: | /* Usage:
scriptname email@to.me "About something" "C:\test.txt" "I wanted to send this email to you about something. Please see the attachment."
*/
var WshShell = WScript.CreateObject("WScript.Shell");
var objArgs = WScript.Arguments
if (objArgs.length != ""){
for (i=0; i < objArgs.length; i++)
{
switch (i){
case 1:
var to = objArgs(i);
break;
case 2:
var subject = objArgs(i);
break;
case 3:
var attach = objArgs(i);
break
case 4:
var body = objArgs(i);
break
default : WshShell.Popup("That is to many arguments!", //message to display
0, //seconds to leave window up; 0 = forever
"What are you thinking?", //title
0+48); //icon + buttons see: http://msdn.microsoft.com/en-us/library/x83z1d9f.aspx;
}
}
var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add('IPM.Note.FormA');
mailItem.Subject = subject;
mailItem.To = to;
mailItem.HTMLBody = body;
mailItem.Attachments.Add(attach)
mailItem.display (0);
outlookNamespace.Logoff;
}
else
{
WshShell.Popup("There are no arguments!", 0, "DUDE!", 0+48);
}
|
Something like that. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|