Forum Discussion

anita_desai's avatar
11 years ago

Main sending through scripts using CDO is not working



Below code i am using for sending mail through scripts. But this code is not working on my machine. but it works on my colleage machine.

Do we require any settings or any dll for the same.


Function SendEmail()



On Error Resume Next



schema = "http://schemas.microsoft.com/cdo/configuration/"



Set mConfig = Sys.OleObject("CDO.Configuration")



mconfig.Fields.Item(strSchema + "sendusing") = 2



mconfig.Fields.Item(strSchema + "smtpserver") = "inbound.tieto.com."



mconfig.Fields.Item(strSchema + "smtpserverport") = 587



mconfig.Fields.Item(strSchema + "smtpauthenticate") = 2



mconfig.Fields.Item(strSchema + "smtpusessl") = false



mconfig.Fields.Item(strSchema + "sendusername") = ""



mconfig.Fields.Item(strSchema + "sendpassword") = ""



mconfig.Fields.Update()



Set mMessage = Sys.OleObject("CDO.Message")



mMessage.Configuration = mconfig



mMessage.From = "anita.desai@tieto.com"



mMessage.To = "anita.desai@tieto.com"



mMessage.Cc = ""



mMessage.Subject = "Test"



mMessage.HTMLBody = "TestMessage"



 



mMessage.Send



End Function








3 Replies

  • vajindarladdad's avatar
    vajindarladdad
    Frequent Contributor
    Hi Anita,

    Corrected your function below.



    Please define the variables that you are going to use in your function.




    Public Function SendEmail()



    On Error Resume Next



    Dim strSchema



    strSchema = "http://schemas.microsoft.com/cdo/configuration/"



    Set mConfig = Sys.OleObject("CDO.Configuration")



    mconfig.Fields.Item(strSchema + "sendusing") = 2



    mconfig.Fields.Item(strSchema + "smtpserver") = "inbound.tieto.com"



    mconfig.Fields.Item(strSchema + "smtpserverport") = 25



    mconfig.Fields.Item(strSchema + "smtpauthenticate") = 2



    'mconfig.Fields.Item(strSchema + "smtpusessl") = false



    'mconfig.Fields.Item(strSchema + "sendusername") = ""



    'mconfig.Fields.Item(strSchema + "sendpassword") = ""



    mconfig.Fields.Update()



    Set mMessage = Sys.OleObject("CDO.Message")



    mMessage.Configuration = mconfig



    mMessage.From = "anita.desai@tieto.com"



    mMessage.To = "anita.desai@tieto.com"



    mMessage.Cc = ""



    mMessage.Subject = "Test"



    mMessage.HTMLBody = "TestMessage"



    mMessage.Send



    On Error GoTo 0



    End Function



     


  • kandharkar_kapi's avatar
    kandharkar_kapi
    Occasional Contributor
    First thing you can do is, turn off your antivirus and try !

    Is still does not work then try with changing domain use yahoo or gmail.

    I would suggest if it is for testing then set up a local mail server using 'hMailServer' and use domain defined in that for mal sending..





  • mark_addinall's avatar
    mark_addinall
    Occasional Contributor
    I use a similar script on several of my test machines to send test result emails, and they all work fine. I would suggest adding err.number and err.description to your watch list and then step through your code.



    Also check that you have the CDO components installed on the machine with the problem.