Hola estoy intentando mandar un email a mi cuenta de gmail.
Despues de pasar un buen rato mirando en google veo que el
codigo esta bien, y tiene que ser por otra razon
Si alguien puede echarme una mano se lo agradecieria
Error: "Error al enviar correo."
Codigo:
Private Function Enviar(ByVal mje As MailMessage) As Integer
Dim smtp As SmtpClient = Nothing
Try
If mje IsNot Nothing Then
smtp = CreateSmtpClient()
If smtp IsNot Nothing Then
smtp.Send(mje)
Return 1
Else
Return -3
End If
Else
Return -2
End If
Catch ex As Exception
_errDesc = Err.Description
Return -1
Finally
smtp = Nothing
End Try
End Function
Private Function CreateMail(ByVal from As String, ByVal displayName As String, ByVal destinatario As String, ByVal asunto As String, _
ByVal body As String, ByVal esHTML As Boolean) As MailMessage
Dim mje As MailMessage = Nothing
Try
mje = New MailMessage
If String.IsNullOrEmpty(displayName) Then
mje.From = New MailAddress(from)
Else
mje.From = New MailAddress(from, displayName)
End If
mje.To.Add(destinatario)
mje.Subject = asunto
mje.Body = body
mje.IsBodyHtml = esHTML
Return mje
Catch ex As Exception
_errDesc = Err.Description
Return Nothing
Finally
mje = Nothing
End Try
End Function
Private Function CreateSmtpClient() As SmtpClient
Dim smtp As SmtpClient = Nothing
Try
smtp = New SmtpClient
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.UseDefaultCredentials = False
_puerto = smtp.Port
Dim aut As String = getAppSettings("autentication")
'Comprueba si el servidor de correo necesita autenticación para las credenciales
If Not String.IsNullOrEmpty(aut) AndAlso aut = True Then
smtp.Credentials = New System.Net.NetworkCredential(
[email protected], password)
End If
smtp.EnableSsl = True
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Return smtp
Catch ex As Exception
_errDesc = Err.Description
Return Nothing
Finally
smtp = Nothing
End Try
End Function