Announcement

Collapse
No announcement yet.

VBS to send mail through Office365

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS to send mail through Office365

    I need a script to send mail from event viewer through Office 365

    I have this script, when running it nothing happens.

    Code:
       Public Function SendEmail()
       
      Set MyEmail = CreateObject("CDO.Message")
       
      MyEmail.Subject = "VBS test mail"
     MyEmail.From = "Office365 sender"
     MyEmail.To = "Receipient"
     MyEmail.TextBody = "this is a test message"
       
      MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
       
      'SMTP Server
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
       
      'SMTP Port
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Office 365 login account"
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Office365 password"
        
     'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
     MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     MyEmail.Configuration.Fields.Update
       
       MyEmail.Send
       
       Set MyEmail = Nothing
       
      End Function

  • #2
    did you write it, or get it from somewhere else?
    Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

    Comment


    • #3
      I got it from the web. What has that got to do with it?

      Comment


      • #4
        I'm curious. you may need to setup a relay:
        http://technet.microsoft.com/en-us/l...xchg.150).aspx
        Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

        Comment


        • #5
          The relay is already there, just need a vb script to do the job.

          Comment


          • #6
            have you tested/confirmed access to port 587 from the host whre this runs?
            Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

            Comment


            • #7
              Yes that has been confirmed.

              Comment


              • #8
                Did you edit the variables for your environment?
                Regards,
                Jeremy

                Network Consultant/Engineer
                Baltimore - Washington area and beyond
                www.gma-cpa.com

                Comment


                • #9
                  Yes of cause I did.

                  Comment


                  • #10
                    Try using port 25 and not 587. Apparently CDO isn't supported.

                    10. Custom applications that use the Outlook MAPI library typically can connect to Exchange Online, but those that use the Exchange Server MAPI Client and Collaboration Data Objects (MAPI/CDO) for server-to-server communication with Exchange will not connect;

                    http://letsexchange.blogspot.com.au/...mitations.html

                    Comment


                    • #11
                      Have tried both ports, cannot get it to Work.

                      Comment


                      • #12
                        try adding
                        Code:
                        dim MyEmail
                        as the first line.

                        Will try and test today.

                        Comment


                        • #13
                          and another thing i've found is that the smtpserver should be your pod server rather than smtp.office365.com

                          http://forums.devshed.com/visual-bas...il-963102.html

                          Comment


                          • #14
                            I have dropped the vbs script, found a powershell script that Works.

                            Comment

                            Working...
                            X