Jump to content

Simple Script Does not work as expected


Jigs
 Share

Recommended Posts

Doing a simple test. I want to open outlook and send "Ctrl-n" to write new mail.

Any Clue.

ShellExecute("outlook.exe","","","",@SW_MAXIMIZE)
WinWait("Outlook")
Sleep(5000)
SendKeepActive("Outlook")
;~ Send("{CTRLDOWN}N{CTRLUP}")
Send("^n")
WinWait("Untitled")
MsgBox(0,"","ok")
Link to comment
Share on other sites

Doing a simple test. I want to open outlook and send "Ctrl-n" to write new mail.

Any Clue.

ShellExecute("outlook.exe","","","",@SW_MAXIMIZE)
WinWait("Outlook")
Sleep(5000)
SendKeepActive("Outlook")
;~ Send("{CTRLDOWN}N{CTRLUP}")
Send("^n")
WinWait("Untitled")
MsgBox(0,"","ok")

I don't have Outlook but I tried this with Outlook Express

WinActivate("Inbox - Outlook")
Sleep(5000)
SendKeepActive("Inbox - Outlook")
;~ Send("{CTRLDOWN}N{CTRLUP}")
Send("^n")
WinWait("New Message")
MsgBox(0,"","ok")

and it worked ok.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

There are better ways to send mails with outlook:

try this one for example:

Local $olMailItem = 0
    Local $olFormatRichText = 3
    Local $olImportanceLow = 0
    Local $olImportanceNormal = 1
    Local $olImportanceHigh = 2
    Local $olByValue = 1
    Local $olFormatHTML = 1
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    $oOMail.Save
    With $oOMail
        .To = ("test1@hp.com")
        .Recipients.Add("test@hp.com")
        .Subject = "some subject"
        .BodyFormat = $olFormatHTML
        .Importance = $olImportanceNormal
        .HTMLBody = "the text of the body"
        .Display
        ;.Send
    EndWith
Link to comment
Share on other sites

@Jigs: You didn't say what happens when you run it.

:)

Sorry, I forgot to mention. Actually nothing happens. I suspect that method Send("^n") might be sending key somewhere else or

its being send to outlook but no reaction from outlook.

Link to comment
Share on other sites

There are better ways to send mails with outlook:

try this one for example:

Local $olMailItem = 0
    Local $olFormatRichText = 3
    Local $olImportanceLow = 0
    Local $olImportanceNormal = 1
    Local $olImportanceHigh = 2
    Local $olByValue = 1
    Local $olFormatHTML = 1
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    $oOMail.Save
    With $oOMail
        .To = ("test1@hp.com")
        .Recipients.Add("test@hp.com")
        .Subject = "some subject"
        .BodyFormat = $olFormatHTML
        .Importance = $olImportanceNormal
        .HTMLBody = "the text of the body"
        .Display
        ;.Send
    EndWith

This seems good alternative option and i tried executing code. but i get outlook security window with "Allow" and "Deny" option.

Link to comment
Share on other sites

Sorry, I forgot to mention. Actually nothing happens. I suspect that method Send("^n") might be sending key somewhere else or

its being send to outlook but no reaction from outlook.

Perhaps Outlook is busy loading itself, and needs a breather before you choke it with more commands. I know my Outlook takes 5 seconds to boot.
Link to comment
Share on other sites

This seems good alternative option and i tried executing code. but i get outlook security window with "Allow" and "Deny" option.

This is security option.You need to adjust you outlook security settings. I suspect that you dont have antivirus software,it is not updated , or it is disabled.Which outlook do you have - 2007?
Link to comment
Share on other sites

I have found that using #include <INet.au3> works flawlessly with my outlook (2007)

_INetMail ( $s_MailTo, $s_MailSubject, $s_MailBody )

then

Send("{ALT}")

Sleep(50)

Send("f")

Sleep(50)

send("e")

to automatically send it.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • 2 weeks later...

This seems good alternative option and i tried executing code. but i get outlook security window with "Allow" and "Deny" option.

The MAPILab Outlook Security Add-on will resolve the Allow and Deny options otherwise you can use this code which acts as a user agent which you can call and close from your main script.

You run it just before you send your email message and close it after the message has been sent.

;//This code runs The Agent

Global $pOutlookAgent = @ScriptDir & "\sOutlookAgent.exe" ;//Outlook Security Program [Run]

Run($pOutlookAgent)

;//This is the Code that Closes the Agent

$PID = ProcessExists($sOutlookAgent)

If $PID Then

Sleep($SleepSLD)

ProcessClose($PID)

EndIf

;//Outlook Agent
Opt("TrayIconHide", 1)          ;//Hide Tray Icon
Opt("WinSearchChildren", 1)     ;Search Children [Windows]

#include <Date.au3>     ;//Date Time Processing

;//Global Variables
Global $Title = "sEmailSMS", $Font = "sans-serif", $FontSize = 10, $FontWeight = 600, $Just = 32, $MsgDuration = 4000, $SysMessage, $sExitTimer = 60000

;//Call the Security Routine
_OutlookAgent()

;//Outlook Security Window Processor
Func _OutlookAgent()
    ;//Start the Exit Timer
    Local $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
    While 1
        ;//Default System Message [Mask]
        $SysMessage = "The User Security Agent will RESPOND TO the" & @CRLF & "'Microsoft Office Outlook' Pop-Up" & @CRLF & @LF & "Please wait..."
        ;//Exit when Time Limit Expires
        If _TimeToTicks(@HOUR, @MIN, @SEC) >= $ExitTimer Then ExitLoop
        ;//Check for Window
        If WinExists("Microsoft Office Outlook", "A program is trying to automatically send e-mail") Then
            ;//Microsoft Office Outlook Window [x, y, width, height]
            $WinSize = WinGetPos("Microsoft Office Outlook", "A program is trying to automatically send e-mail")
            SplashTextOn($Title, $SysMessage, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $Font, $FontSize, $FontWeight)
            WinActivate("Microsoft Office Outlook")
            While 1
                If ControlCommand ("Microsoft Office Outlook","A program is trying to automatically send e-mail","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ;//Message Timer
                    Sleep ($MsgDuration)
                    ;//Switch Message Off
                    SplashOff()
                    ExitLoop
                EndIf
            WEnd
            ;//Reset Exit Timer [Allow OutlookAgent to stay active until all Pop-Ups are Processed]
            $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
        EndIf
        ;//Check for Window
        If WinExists("Microsoft Office Outlook", "A program is trying to access e-mail addresses you have stored in Outlook") Then
            $WinSize = WinGetPos("Microsoft Office Outlook", "A program is trying to access e-mail addresses you have stored in Outlook")
            SplashTextOn($Title, $SysMessage, $WinSize[2], $WinSize[3], $WinSize[0], $WinSize[1], $Just, $Font, $FontSize, $FontWeight)
            WinActivate("Microsoft Office Outlook")
            While 1
                If ControlCommand ("Microsoft Office Outlook","A program is trying to access e-mail addresses you have stored in Outlook","Button4","IsEnabled") Then
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:3]")
                    Send ("{SPACE}")
                    Sleep (500)
                    ControlFocus ("Microsoft Office Outlook","","[CLASS:Button; INSTANCE:4]")
                    Send ("{SPACE}")
                    ;//Message Timer
                    Sleep ($MsgDuration)
                    ;//Switch Message Off
                    SplashOff()
                    ExitLoop
                EndIf
            WEnd
            ;//Reset Exit Timer
            $ExitTimer = _TimeToTicks(@HOUR, @MIN, @SEC) + $sExitTimer
        EndIf
        Sleep(1000)
    WEnd
    ;//Exit when Time Limit Expires  [Note: If running a 'ProcessClose' is Executed by the Calling Program]
    Exit
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...