0

I have a script were an email has to be sent. The email comes from the user and is not properly checked. So I have discovered that when the email is sent the following error occurs "CDO.Message.1: The "SendUsing" configuration value is invalid." and it is displayed as a message box.

In order to avoid this I thought that I could use "on error resume next" but it seems that it does not work, because after the send command the Err object is 0. I tried also the Err.Number and its also 0

The script runs automatically in the background so an error message is not acceptable but also just placing "on error resume next" without knowing that an error occurred is still not acceptable.

Is there a way of knowing that the CDO.Message.Send has failed but without presenting a dialog box.

It seems that some people did not understood my problem. Here is an example

Set EMail = CreateObject("CDO.Message")
    
EMail.Subject = "Just for test"

EMail.HTMLBody = "..."

' this comes from another place
EMail.TO = "49 (9132) 82-72 9743@xxx"
EMail.CC = ""
EMail.BCC = ""

With EMail.Configuration.Fields
    .Item(Schema & "sendusing") = 2
    .Item(Schema & "smtpserver") = "..." 
    .Item(Schema & "smtpserverport") = 25
    .Update
End With

on error resume next
EMail.Send

' this line prints The error was 0 even though the email is not valid and the Send was not successfull
WScript.Echo "The error was " & Err.Number

If you comment the on error resume next you get the error displayed "CDO.Message.1: The "SendUsing" configuration value is invalid."

Dan
  • 683
  • 2
  • 8
  • 24
  • 1
    Does this answer your question? [VBScript -- Using error handling](https://stackoverflow.com/questions/157747/vbscript-using-error-handling) – user692942 Apr 08 '21 at 08:18
  • I already did that but the Err = 0 and Err.Number = 0 even though an error appeared. So no. I already saw that before – Dan Apr 08 '21 at 09:25
  • 2
    You need to check `Err.Number <> 0` directly after the line that triggers the error which will probably be the `Update()` method call of the `CDO.Configuration` object before `Send()` is even called. – user692942 Apr 08 '21 at 09:32
  • 2
    You are correct. If I place the resume next before the update I get the error – Dan Apr 08 '21 at 10:15
  • Also as a correction after the Update method the error number remains 0. so it does not work as you said. Could it be because of the with syntax!?! – Dan Apr 08 '21 at 14:02
  • Because the `Err` object is evaluated line by line that's how it works which is why you have to check directly after the line you think is causing the error. – user692942 Apr 08 '21 at 14:24

0 Answers0