Jump to content
Sign in to follow this  
MrAutomationGuy

SendMail doesn't work with RunWait on Windows 2003

Recommended Posts

MrAutomationGuy

Hi,

My First thread....Yeah.

First I want to thank the AutoIT team for a great job, I have become a fan and I use it on a daily bases.

Here is my issue ....

I have an AutoIT script, which generate a VBS script, Executes the "RunWait" and Executes that VBS scripts to send an Email to a user. This scripts works on 24 hosts that are 2008, Windows7 but Windows 2003.

TIn Windows 2003, If I double click on "C:SendEmail.VBS" in Windows Explorer, it will successfully send the email. However, if I run it with my AutoIT Script(C;SendEmail.Au3), no errors is returned, and no Email is sent either.

I have included my autoit and vbs script code in here. any thoughts??

The VBS Script:

'___________SendEmail.vbs____________________

On Error Resume Next

Set objShell = Wscript.CreateObject("Wscript.Shell")

Dim strEventText

LogFile "Sending an Email Started..........."

sendMail "Site Admin<Administrator@site.com>", admin@site.com, "Testing.....blah blah", "Attention, Your Host blah blah...1403"

' ----- Success exit ------'

WSscript.Quit(0)

' ----- Local Subroutines ------'

Function sendMail(strFrom, strTo, strSubject, strMail)

On Error Resume Next

oMailServer = "myex.site.com"

Set objEmail = CreateObject("CDO.Message") '<--- I think the issue happens here, doesn't create the CDO object.

objEmail.From = strFrom

objEmail.To = strTo

objEmail.Subject = strSubject

objEmail.Textbody = strMail

If strMailFile = 1 Then

objEmail.AddAttachment strAttachment

End If

If Err.Number <> 0 Then

WScript.StdOut.Write "ERROR: Unable to create CD Object." & vbCrLf & "Error Number [" & Err.Number & "]"& vbCrLf & "Error description: [" & Err.Description & "]"

WSscript.Quit(-1)

End If

objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

oMailServer

objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _

= 25

objEmail.Configuration.Fields.Update

objEmail.Send

If Err.Number <> 0 Then

WScript.StdOut.Write "ERROR: Unable to send Email." & vbCrLf & "Error Number [" & Err.Number & "]"& vbCrLf & "Error description: [" & Err.Description & "]"

WSscript.Quit(-1)

Else

WScript.StdOut.Write("Sent Email Successfully.") & vbCrLf

End If

End Function

'----------------------- End of SendEmail.VBS -------------------

The SendEmail.Au3

Global $strTaskScriptPath = "C:TempSendEmail.vbs > C:TempSendEmail.log 2>&1"

;Execute The VBS

Local $retStr = RunWait(@ComSpec & " /c " & Chr(34) & $strTaskScriptPath& Chr(34), "C:Temp", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

Thanks in advance,

MrAutomationGuy

;

Edited by MrAutomationGuy

Share this post


Link to post
Share on other sites
water

Why do you use a VBS? AutoIts builtin function _INetSmtpMail should do the same without the need to use RunWait plus return additional error information.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrAutomationGuy

Good Suggestion, I will try it. But how do you send Attachments with INetSmtpMail? Isn't that just a simple SMTP Mail protocal? unless I'm missing something.

But my question was mostly on using "RunWait" On 2003. Is there any issues with it?

Edited by MrAutomationGuy

Share this post


Link to post
Share on other sites
water

There is a modified version of INetSmtpMail available that lets you send attachments -

I don'tbelieve there is a problem with RunWait on Windows 2003.

@SW_SHOW isn't a valid flag according to the docu. $STDERR_CHILD + $STDOUT_CHILD aren't allowed with RunWait - only with Run.

Could you please try this modified version?

Global $strTaskScriptPath = "C:\Temp\SendEmail.vbs > C:\Temp\SendEmail.log 2>&1"
;Execute The VBS
Local $retStr = RunWait(@ComSpec & " /c " & $strTaskScriptPath, "C:\Temp", @SW_MAXIMIZE)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrAutomationGuy

Thank you I got it to work with INetSmtpMail.

Question. I found some bugs with INetSmtpMail script and fixed them. I also enhanced how it returns the errors. What's the process of me releasing to the review commuty?

Edited by MrAutomationGuy

Share this post


Link to post
Share on other sites
water

I would open a thread to discuss the issue. I'm not sure if such a thread belongs in the General Help and Support or the Developer Chat forum.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrAutomationGuy

Thank Will do.

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  

×