I'm trying to send mails using VBA code. We deleted the display method but it is still not working.
It displays the email with every property of the object Correo, but it's not sending.
It raises error 438.
Sub sendmail(propietario As String, activo As String, departamento As String)
Dim OutApp As Object
Dim Correo As Object
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
On Error Resume Next
Set OutApp = GetObject("", "Outlook.Application")
Err.Clear
If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
OutApp.Visible = True
Set Correo = OutApp.CreateItemFromTemplate("C:\Users\plantilla.oft")
With Correo
.To = propietario
.CC = "mail@gmail.com"
.Subject = "[Recertificación de Usuarios] " & activo & " - " & departamento
.Attachments.Add "C:\Users\hello.xlsx"
Set .SendUsingAccount = OutApp.Session.Accounts.Item(1)
.Display
.Send
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set Correo = Nothing
Set OutApp = Nothing
End Sub