Jump to content
Sign in to follow this  
KevinECC

How To Send But NOT Open via INetMail ?

Recommended Posts

KevinECC

HI AUtoIt Forumners,

How do I send an automated email via INetMail function without the mail being opened in "draft" mode

and waiting for me to hit the "SEND" key ? The following script is scheduled to run at certain time to

check file "ZCT.TRANFILE" existence in the "Failed-Upload" directory. If the file exists, I want to send the

warning email. However, the mail is opened and waits for me to hit the "SEND" key while I only want it

to send without my intervention.

Please help.

Kevindtran55@yahoo.com

include <Inet.au3>

$Address = "kevinecc@yahoo.com"

$Subject = "Application ZCTTRAN Programs Failed Upload"

$Body = "Hey Kevin, your ZCTTRAN upload Failed !"

If FileExists("C:\XAPCOM\ZCTTRAN\Failed-Upload\ZCT.TRANFILE") Then

_INetMail($address, $subject, $body)

Else

EndIf

Share this post


Link to post
Share on other sites
Varian

Can you not use _INetSmtpMail ? _INetMail says in the Help file:

Opens default user's mail client with given address, subject, and body.

if you must use that function then it would seem that you'll have to automate clicking send

Share this post


Link to post
Share on other sites
Andreik

Via Telnet:

Func Mail($SMTP,$Name,$From,$To,$Subject,$Body)
Local $RETURN
Local $DATA[14]
$DATA[0] = 13
$DATA[1] = "HELO " & $Name & @CRLF
$DATA[2] = "MAIL FROM: <" & $From &">" & @CRLF
$DATA[3] = "RCPT TO: <" & $To &"> "& @CRLF
$DATA[4] = "DATA" & @CRLF
$DATA[5] = "From:" & $Name & "< " & $From &" >" & @CRLF
$DATA[6] = "To:" & $To & @CRLF
$DATA[7] = "Subject:" & $Subject & @CRLF
$DATA[8] = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF
$DATA[9] = "Mime-Version: 1.0" & @CRLF
$DATA[10] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF
$DATA[11] = @CRLF
$DATA[12] = $Body & @CRLF
$DATA[13] = "." & @CRLF
TCPStartUp()
$SOCKET = TCPConnect(TCPNameToIP($SMTP),25)
If $SOCKET = -1 Then Exit
For $INDEX = 1 To $DATA[0]
    $RETURN = TCPSend($SOCKET,$DATA[$INDEX])
    Sleep(100)
Next
Return $RETURN
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites
KevinECC

Varian wrote :

>Can you not use _INetSmtpMail ? _INetMail says in the Help file:

>Opens default user's mail client with given address, subject, and body."

Hi Varian,

_INetSmtpMail was my first choice, but somehow it didn't work ! nothing was sent and no email was

opened in the "draft" mode.

Here is my first version using _INetSmtpMail :

#include <Inet.au3>

$s_SmtpServer = "mail.learning.edu"

$s_FromName = "AutoItPrince"

$s_FromAddress = "mailinh@learning.edu"

$s_ToAddress = "kevindtran55@yahoo.com"

$s_Subject = "ZCTTRAN Failed Upload"

$s_Body = "Kevin, your CCCTRAN Upload Failed"

If FileExists("C:\TRANSTEST-ZCTTRAN\AutoIt-Test\CCC.ZCTTRAN") Then

_INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body)

MsgBox(4096, "","ZCTTRAN File Existed")

Else

MsgBox(4096, "","ZCTTRAN Uploaded OK")

EndIf

For this version, the first message "ZCTTRAN File Existed" is displayed properly but nothing is sent.

That's why I tried _INetMail.

>if you must use that function then it would seem that you'll have to automate clicking send

How do you do that ? is there an AutoIt example ? I searched the "Send" function reference and I saw things like :

"Send", "SendAttachMode", "SendKeyDelay" ... but couldn't find anything I can use.

Andreik also posted about 20 lines of codes for the "Mail" function as listed below. I don't really understand what it

supposes to do but I'll copy these lines into my AutoIt and try it. I'm an AutoIt newbie so please forgive my primitive

knowledge and stupidity.

Thanks.

Kevin

Func Mail($SMTP,$Name,$From,$To,$Subject,$Body)

Local $RETURN

Local $DATA[14]

$DATA[0] = 13

$DATA[1] = "HELO " & $Name & @CRLF

$DATA[2] = "MAIL FROM: <" & $From &">" & @CRLF

$DATA[3] = "RCPT TO: <" & $To &"> "& @CRLF

$DATA[4] = "DATA" & @CRLF

$DATA[5] = "From:" & $Name & "< " & $From &" >" & @CRLF

$DATA[6] = "To:" & $To & @CRLF

$DATA[7] = "Subject:" & $Subject & @CRLF

$DATA[8] = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF

$DATA[9] = "Mime-Version: 1.0" & @CRLF

$DATA[10] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF

$DATA[11] = @CRLF

$DATA[12] = $Body & @CRLF

$DATA[13] = "." & @CRLF

TCPStartUp()

$SOCKET = TCPConnect(TCPNameToIP($SMTP),25)

If $SOCKET = -1 Then Exit

For $INDEX = 1 To $DATA[0]

$RETURN = TCPSend($SOCKET,$DATA[$INDEX])

Sleep(100)

Next

Return $RETURN

EndFunc

Share this post


Link to post
Share on other sites
Varian

What is your default email client? Outlook? what version?

Share this post


Link to post
Share on other sites
KevinECC

Varian wrote :

>Can you not use _INetSmtpMail ? _INetMail says in the Help file:

>Opens default user's mail client with given address, subject, and body."

Hi Varian,

_INetSmtpMail was my first choice, but somehow it didn't work ! nothing was sent and no email was

opened in the "draft" mode.

Here is my first version using _INetSmtpMail :

#include <Inet.au3>

$s_SmtpServer = "mail.learning.edu"

$s_FromName = "AutoItPrince"

$s_FromAddress = "mailinh@learning.edu"

$s_ToAddress = "kevindtran55@yahoo.com"

$s_Subject = "ZCTTRAN Failed Upload"

$s_Body = "Kevin, your CCCTRAN Upload Failed"

If FileExists("C:\TRANSTEST-ZCTTRAN\AutoIt-Test\CCC.ZCTTRAN") Then

_INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body)

MsgBox(4096, "","ZCTTRAN File Existed")

Else

MsgBox(4096, "","ZCTTRAN Uploaded OK")

EndIf

For this version, the first message "ZCTTRAN File Existed" is displayed properly but nothing is sent.

That's why I tried _INetMail.

>if you must use that function then it would seem that you'll have to automate clicking send

How do you do that ? is there an AutoIt example ? I searched the "Send" function reference and I saw things like :

"Send", "SendAttachMode", "SendKeyDelay" ... but couldn't find anything I can use.

Andreik also posted about 20 lines of codes for the "Mail" function as listed below. I don't really understand what it

supposes to do but I'll copy these lines into my AutoIt and try it. I'm an AutoIt newbie so please forgive my primitive

knowledge and stupidity.

Thanks.

Kevin

Func Mail($SMTP,$Name,$From,$To,$Subject,$Body)

Local $RETURN

Local $DATA[14]

$DATA[0] = 13

$DATA[1] = "HELO " & $Name & @CRLF

$DATA[2] = "MAIL FROM: <" & $From &">" & @CRLF

$DATA[3] = "RCPT TO: <" & $To &"> "& @CRLF

$DATA[4] = "DATA" & @CRLF

$DATA[5] = "From:" & $Name & "< " & $From &" >" & @CRLF

$DATA[6] = "To:" & $To & @CRLF

$DATA[7] = "Subject:" & $Subject & @CRLF

$DATA[8] = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF

$DATA[9] = "Mime-Version: 1.0" & @CRLF

$DATA[10] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF

$DATA[11] = @CRLF

$DATA[12] = $Body & @CRLF

$DATA[13] = "." & @CRLF

TCPStartUp()

$SOCKET = TCPConnect(TCPNameToIP($SMTP),25)

If $SOCKET = -1 Then Exit

For $INDEX = 1 To $DATA[0]

$RETURN = TCPSend($SOCKET,$DATA[$INDEX])

Sleep(100)

Next

Return $RETURN

EndFunc

Share this post


Link to post
Share on other sites
KevinECC

I use Microsoft Outlook 2003 (11.8217.8221) SP3.

Share this post


Link to post
Share on other sites
Varian

Try this..the only thing you'll have to see is whether any windows will popup after sending it. (Security, Spelling, etc.)

#include <Inet.au3>

$Address = "kevinecc@yahoo.com"
$Subject = "Application ZCTTRAN Programs Failed Upload"
$Body = "Hey Kevin, your ZCTTRAN upload Failed !"

If FileExists("C:\XAPCOM\ZCTTRAN\Failed-Upload\ZCT.TRANFILE") Then
    _INetMail($Address, $Subject, $Body)
    ;wait for Outlook Window with The title as the Subject via Regexp...used \Q \E in case there are funky characters in the Subject
    WinWait("[REGEXPTITLE:(?i)\Q" & $Subject & "\E; CLASS:OpusApp]", "", 10)
    Sleep(1000)
    ControlSend("[REGEXPTITLE:(?i)\Q" & $Subject & "\E; CLASS:OpusApp]", "", "", "!s") ;Send Alt-S to Send, window does not need focus
Else
EndIf

Use Au3InfoTool if the class does not match your outlook window

Share this post


Link to post
Share on other sites
KevinECC

Varian,

I inserted your new codes (with WinWait and ControlSend commands) into my Autoit codes. However there was no different ! the mail was opened

in "draft" mode again, ready for me to send. The mail would actually send only after I click on the "send button" or did an "Alt-S".

There was no windows popup after the mail is sent.

I think we're getting closer to the solution. We just need to find the proper way to execute an "Alt-S" via "ControlSend".

Share this post


Link to post
Share on other sites
Varian

Use Au3InfoTool to get the tile & class of your mail client window. I'm not sure if the Title of your window is "Draft", but mine came up to the Subject name. If the title is "Draft", you can change the

"[REGEXPTITLE:(?i)\Q" & $Subject & "\E; CLASS:OpusApp]"

to

("[TITLE:Draft; CLASS:OpusApp]"

Or whatever the classname that comes up over your window(it should be the same, though)...I can only guess that your title is different so the Winwait times out after 10 seconds and the ControlSend sens alt-s to a nonexistent window

Share this post


Link to post
Share on other sites
Andreik

$Smtp = "66.196.97.250"
$Address = "kevinecc@yahoo.com"
$Subject = "Application ZCTTRAN Programs Failed Upload"
$Body = "Hey Kevin, your ZCTTRAN upload Failed !"

If FileExists("C:\XAPCOM\ZCTTRAN\Failed-Upload\ZCT.TRANFILE") Then
    $MAIL = Mail($Smtp,"Kevin","user@yahoo.com","kevinecc@yahoo.com",$Subject,$Body)
    If $MAIL = 3 Then 
        MsgBox(0,"","Message was send")
    Else
        MsgBox(0,"","Error")
    EndIf
EndIf

Func Mail($SMTP,$Name,$From,$To,$Subject,$Body)
Local $RETURN
Local $DATA[14]
$DATA[0] = 13
$DATA[1] = "HELO " & $Name & @CRLF
$DATA[2] = "MAIL FROM: <" & $From &">" & @CRLF
$DATA[3] = "RCPT TO: <" & $To &"> "& @CRLF
$DATA[4] = "DATA" & @CRLF
$DATA[5] = "From:" & $Name & "< " & $From &" >" & @CRLF
$DATA[6] = "To:" & $To & @CRLF
$DATA[7] = "Subject:" & $Subject & @CRLF
$DATA[8] = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF
$DATA[9] = "Mime-Version: 1.0" & @CRLF
$DATA[10] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF
$DATA[11] = @CRLF
$DATA[12] = $Body & @CRLF
$DATA[13] = "." & @CRLF
TCPStartUp()
$SOCKET = TCPConnect(TCPNameToIP($SMTP),25)
If $SOCKET = -1 Then Exit
For $INDEX = 1 To $DATA[0]
$RETURN = TCPSend($SOCKET,$DATA[$INDEX])
Sleep(100)
Next
Return $RETURN
EndFunc


When the words fail... music speaks

Share this post


Link to post
Share on other sites
KevinECC

Varian wrote :

>Use Au3InfoTool to get the tile & class of your mail client window ...

Is "Au3InfoTool" an "#include" file ? I tried to include it but gor a comping error : "Error Reading the File Au3InfoTool" !

BTW, I tried Andreik's attached codes and it worked perfectly ! thank you so much Andreik. But I also want to try

Varian's suggestions so I can learn more about AutoIT.

Thanks.

Share this post


Link to post
Share on other sites
Varian

If you have installed SciTe then you will have Au3InfoTool. It is an application that shows you what the title and handles are for windows and controls within them. Use that to find out what the Window Title & Class are for your Draft message. I have included a screenshot of what I mean.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.