Hello,
So far, I am succesfully using this code to send emails via Outlook
Code:
Public Sub EnviarEmail(strEmail As String, strAsunto As String, srtCuerpoEmail As String, Optional strAdjunto As String)
Dim olApp As Object
Dim objMail As Object
Dim aArchivosAdjuntos() As String
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = strEmail
.Subject = strAsunto
.HTMLBody = srtCuerpoEmail
If Not IsNull(strAdjunto) Then
aArchivosAdjuntos = Split(strAdjunto, ";")
For i = LBound(aArchivosAdjuntos) To UBound(aArchivosAdjuntos)
.Attachments.Add aArchivosAdjuntos(i), olByValue, , "My Displayname"
Next i
End If
.Send
DoEvents
End With
Set olApp = Nothing
Set objMail = Nothing
MsgBox "Email enviado con éxito"
End Sub
When I introduced it, it was in another computer and worked fine. In the PC I am currently using my program, it only works if I manually open Outlook. Then it sends all the emails in the queue. As I understand the code, it is supposed to be able to launch the program. Could it be that is beeing blocked?
Another question. This code gives a sort of confirmation when it finishes. This confirmation is totally virtual. Is there anyway to get an actual confirmation from outlook that the email is really sent?
Thank you very much.