Forum Discussion

paarmann-ara's avatar
paarmann-ara
Contributor
5 years ago
Solved

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?

  • paarmann-ara's avatar
    paarmann-ara
    5 years ago

    Good day,

    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

     

    https://www.rosettacode.org/wiki/Send_email#Python

     

    maybe that is better to attache that codes in TC's help. :-)

     

     

19 Replies

  • LinoTadros's avatar
    LinoTadros
    Community Hero

    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

      • LinoTadros's avatar
        LinoTadros
        Community Hero

        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 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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"

     

    • paarmann-ara's avatar
      paarmann-ara
      Contributor

      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)
      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        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.