send mail via script
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
send mail via script
Good Day,
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what is the error?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Cheers
Lino
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@anupamchampati @LinoTadros Many thanks for your quick reply
('The transport could not connect to the server.', 0, 'CDO.Message.1', '', 0, -2147220973)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Cheers
-Lino
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I must using the STARTTLS.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@tristaanogre Thanks,
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.
