(Solved) – Can’t send E-mail with VBA

(solved)-–-can’t-send-e-mail-with-vba

I’m work using VBA for sending Email automation.When E-mail send it not attach file to Email.

This’s my some VBA code :

   Set iMsg = CreateObject("CDO.Message")
   Set iConf = CreateObject("CDO.Configuration")
   Set objFSO = CreateObject("Scripting.FileSystemObject")

       iConf.Load -1    ' CDO Source Defaults
       Set Flds = iConf.Fields
       With Flds
          .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.45.1.25"
          .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          .Update
       End With
       Dim Result() As String
       Dim xAttaches As String

      Result = Split(WorksheetFunction.Trim(xAttached), "|")

  With iMsg
      Set .Configuration = iConf
      .To = "Veerachai.M@ngerntidlor.com"
      .CC = 
      .From = "finrobo@ngerntidlor.com"
      .Subject = xSubject
      .HTMLBody = RangetoHTML(rng) & strBody
       For i = LBound(Result()) To UBound(Result())
         xAttaches = "R:ASMP0_AP_AUTO_MAIL202003BARCODEIE238182.pdf"
        If objFSO.FileExists(xAttaches) Then
          iMsg.AddAttachment "R:ASMP0_AP_AUTO_MAIL202003BARCODEIE238182.pdf"
        End If
     Next i
      iMsg.Send
  End With

  With Application
      .EnableEvents = True
      .ScreenUpdating = True
  End With

  Set iMsg = Nothing
  Set iConf = Nothing
  Set Flds = Nothing
End Function

My code can run and can send Email. Like this :

enter image description here

But I need Attach file in E-mail.Like this :

enter image description here

Please tell me how to solve this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *