I try send mail via script, but I get error.
def SendEmail(Message): try: useSSL = 'True' schema = "http://schemas.microsoft.com/cdo/configuration/" mConfig = Sys.OleObject["CDO.Configuration"] mConfig.Fields.Item[schema + "sendusing"] = 2 mConfig.Fields.Item[schema + "smtpserver"] = outlook.office365.com mConfig.Fields.Item[schema + "smtpserverport"] = 587 mConfig.Fields.Item[schema + "sendusername"] = MyEmailAddress mConfig.Fields.Item[schema + "sendpassword"] = MyEmailPassword mConfig.Fields.Item[schema + "smtpauthenticate"] = 1 mConfig.Fields.Item[schema + "STARTTLS"] = True mConfig.Fields.Item[schema + "smtpconnectiontimeout"] = 30; mConfig.Fields.Update() mMessage = Sys.OleObject["CDO.Message"] mMessage.Configuration = mConfig mMessage.From = MyEmailAddress mMessage.To = MyEmailAddress mMessage.Subject = 'TestComplete Result' mMessage.HTMLBody = Message mMessage.Send(); except Exception as exp: Log.Error('E-mail cannot be sent', str(exp)) return False Log.Message('Message was successfully sent') return True def test (): SendEmail('Hi')
Wht is wrong in my code?
Solved! Go to Solution.
After days and days, I have find a solution for this problem.
The CDO do not support TLS therefor this problem apear in my Case. I use another codes from this Link
maybe that is better to attache that codes in TC's help. 🙂
Any reason you are not using the Builtin.SendMail( ) function in Testcomplete instead of using the CDO objects?
Also without sharing the error, it is difficult to help
It would be helpful to know what the error is you get and on which line.
Just as a rough guess, though, if this is a copy and paste of your actual code the problem is with
mConfig.Fields.Item[schema + "smtpserver"] = outlook.office365.com
That needs to be set as a string. Change to
mConfig.Fields.Item[schema + "smtpserver"] = "outlook.office365.com"
That is not a TestComplete issue. You have a problem on the machine you are executing this code from regarding the CDO COM object registration, or Firewall.
To eliminate the possible issues, try to execute the code from your Python IDE of choice and you will probably get the same error.
If you have Visual Studio, you can try similar code in C# to send a message with CDO
Once you are successful using the CDO object in another product, TestComplete will work.
You can even use Excel with VBScript to test the CDO object
Currently I am pretty sure it is the COM server for CDO or the Firewall that is cause the connection not to work
@tristaanogre many thanks for your Tip,
I change it with "outlook.office365.com"
and agin not working
the error ist:
('The transport could not connect to the server.', 0, 'CDO.Message.1', '', 0, -2147220973)
There are other things in that code that I'm assuming are variables. MyEmailAddress and MyEmailPassword for example. The assumption is that they are being populated somewhere. Please check to make sure you have those values correct.
I check that, that is correct. So, Maybe the case of this Error is our Firewall and hosting department. I will try this code from another infrastructure.
Get properties of a web page element
Compare images using the Region Checkpoint
Compare HTML table with Excel file and correct data in Excel file
How to execute remote test and obtain results via Test Runner REST API