How to obtain text error information from CDO.Message call

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I want to capture the text description of a message that is triggered by an error trying to send an email message using CDO.Message in a vbscript. Here is the script:
Dim sMessage<br/>
dim rc<br/>
sMessage = "press OK to send email" <br/>
Display the text in a messagebox<br/>
Msgbox sMessage<br/>
rc=fnSendEmail<br/>
msgbox "return code from fnsendemail is " & rc<br/>
wscript.quit rc
Function fnSendEmail() <br/>
Create an object of CDO type<br/>
Set myMail=CreateObject("CDO.Message")<br/>
Enable SSL Authentication<br/>
myMail.Configuration.Fields.Item(" http://schemas.microsoft.com/cdo/configuration/smtpusessl http://schemas.microsoft.com/cdo/configuration/smtpusessl ") = True<br/>
Enable basic smtp authentication<br/>
myMail.Configuration.Fields.Item(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ") = 1<br/>
Specify Yahoo SMTP server and Port Number<br/>
myMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/smtpserver http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.mail.yahoo.com "<br/>
myMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/smtpserverport http://schemas.microsoft.com/cdo/configuration/smtpserverport ") = 465<br/>
myMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/sendusing http://schemas.microsoft.com/cdo/configuration/sendusing ") = 2<br/>
Specify user id and password<br/>
myMail.Configuration.Fields.Item(" http://schemas.microsoft.com/cdo/configuration/sendusername http://schemas.microsoft.com/cdo/configuration/sendusername ") = " mailto:me@yahoo.com me@yahoo.com "<br/>
myMail.Configuration.Fields.Item(" http://schemas.microsoft.com/cdo/configuration/sendpassword http://schemas.microsoft.com/cdo/configuration/sendpassword ") = "mypassword"<br/>
Update the configuration fields<br/>
myMail.Configuration.Fields.Update <br/>
Specify email properties<br/>
myMail.Subject = "Sending Email from QTP"<br/>
myMail.From = " mailto:me@yahoo.com me@yahoo.com "<br/>
myMail.To = " mailto:metoo@insight.rr.com metoo@insight.rr.com "<br/>
myMail.CC = ""<br/>
myMail.BCC = ""<br/>
myMail.TextBody = "This is the Text Body"<br/>
Send 2 attachments in the mail<br/>
myMail.AddAttachment "D:Attachment1.txt"<br/>
myMail.AddAttachment "D:Attachment2.txt" <br/>
Send mail<br/>
on error resume next<br/>
myMail.Send<br/>
If err.Number <> 0 Then <br/>
MsgBox err.Number & " - " & err.Description<br/>
fnSendEmail = err.Number<br/>
else<br/>
msgbox "Mail sent OK"<br/>
fnSendEmail = 0<br/>
end if<br/>
Set myMail = Nothing <br/>
End Function
I run the vbs script from a perl script:
use strict; <br/>
use warnings;
print STDERR "Execute vbscript to send mail using yahoo loginn";<br/>
my $cmd=q{"C:UsersOwnersend email using yahoo (redacted).vbs"};<br/>
print STDERR "Command is:$cmdn";<br/>
`$cmd`;<br/>
if ($? != 0) {<br/>
print STDERR "send email failed: return code is ", $? >> 8, ", process signal was ", $? & 127, "n";<br/>
}<br/>
else {<br/>
print STDERR "send email was successfuln";<br/>
}
C:UsersOwnerNWCC perl>perl "C:UsersOwnersend yahoo email.pl"<br/>
Execute vbscript to send mail using yahoo login<br/>
Command is:"C:UsersOwnersend email using yahoo (redacted).vbs"<br/>
send email failed: return code is 17, process signal was 0
Is it possible to reflect back to the perl script the text description from the error message?
Here is an example of the error message box:
https://skydrive.live.com/redir.aspx?cid=2995939bbc5ef395&resid=2995939BBC5EF395!166&parid=2995939BBC5EF395!126&authkey=!AHec7ul-4IPda7w https://skydrive.live.com/redir.aspx?cid=2995939bbc5ef395&resid=2995939BBC5EF395!166&parid=2995939BBC5EF395!126&authkey=!AHec7ul-4IPda7w
<img alt="" src="https://skydrive.live.com/redir.aspx?cid=2995939bbc5ef395&resid=2995939BBC5EF395!166&parid=2995939BBC5EF395!126&authkey=!AHec7ul-4IPda7w
TIA,
Phil
<br/>
<br/>
<br/>

View the full article
 
Back
Top