1 Reply Latest reply on Apr 24, 2015 8:58 AM by SH_INT

    Attaching multi-load file to e-mail after loading


      I have the below script which is used to attach and e-mail monthly TB files after they have been loaded.  I use it in the AftConsolidate event.  We also load multi-load files and would like to have that file attached to an e-mail as well.  Has anyone ever done this?  I am unable to get it to work.


      Dim strFromAddress
      Dim strToAddress
      Dim strSubject
      Dim strEmailMsgLine
      Dim objMsg
      Dim objConfig
      Dim intSendUsing
      Dim strSMTPServer
      Dim intSendPort
      Dim strAttach


      If Right(LCase(strFile), 5) = "a.dat" Then
              Exit Sub
      End If

      If Right(LCase(strFile), 5) = "b.dat" Then
              Exit Sub
      End If

      If Right(LCase(strFile), 5) = "c.dat" Then
              Exit Sub
      End If


      LocationNumber = RES.PlngLocKey


      'All Brands
      If LocationNumber = 767 Or _
         LocationNumber = 924 Then


      LocationName = RES.PstrLoc
      LocationPeriod = RES.PstrPer
      LocationCategory = RES.PstrCat



      'Initialize message content variables
      strFromAddress = DW.Security.fUserEmailGet(DW.Connection.PstrUserID)
      strToAddress = "XXXXXXXX.com"
      strSubject = LocationName & " " & LocationPeriod & " " & LocationCategory & " has been loaded."
      strEmailMsgLine = ""


      'InitializeAPI.SQLUpdateMgr.fStructPartitionStructures(strStructureID, blnAppend, lngMarshalType) Mail Server variables
      'SMTP server name
      strSMTPServer = "XXX.com"

      'CdoSendUsing enumeration-1=use smtp on local machine, 2=use smtp over network
      intSendUsing = 2

      'SMTP port on server
      intSMTPPort = 25


      'Create CDO configuration object
      Set objConfig = CreateObject("CDO.Configuration") 

      'Set Config object settings
      With objConfig.Fields
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = intSendUsing
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= intSMTPPort
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
      End With


      'Create CDO message object
      Set objMsg = CreateObject("CDO.Message")

      'Assign config object to configuration property of message object
      Set objMsg.Configuration = objConfig

      'Set Message object settings and send mail
      strAttach = API.MaintenanceMgr.fPartLastFile(strloc, True, False)

      ' Message object settings and send mail
      With objMsg
      .To = strToAddress
      .From = strFromAddress
      .Subject = strSubject


      ' Path to source file
      strAttach = Trim(strAttach)


      ' Attach file to message
      If Not strAttach="" Then
        Set fso = CreateObject("Scripting.FileSystemObject")
      If fso.FileExists(strAttach) Then .AddAttachment strAttach
        Set fso = Nothing
      End If

      .TextBody = strEmailMsgLine
      End With


      'Destroy message objects
      Set objMsg = Nothing
      Set objConfig = Nothing


      End If