I have made a form to send emails, I used this code I found somewhere:
Code:
Private Sub cmdEnviarOutlook_Click()
Call EnviarEmail(Me.txtEmail, Me.txtAsuntoEmail, Me.txtLeyenda)
End Sub
Code:
Public Sub EnviarEmail(strEmail As String, strAsunto As String, srtCuerpoEmail As String)
Dim olApp As Object
Dim objMail As Object
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
.Send
End With
Set olApp = Nothing
Set objMail = Nothing
MsgBox "Email enviado con éxito"
End Sub
I configured Outlook with my gmail account.
The code works fine (after adding references) but when I take a look to the sent-box in Gmail, I find that the email is duplicated.
Why is this happening?
If I send an email normally or even using docmd.sendobject, that doesn't happen.
One more question. I tried this function in two computers and in one of them Outlook asks for permission while it does not in the other one. I believe it is related with Outlook config. Where can I change this??
Thanks in advance.