Foros del Web » Programando para Internet » ASPX (.net) »

Mandar Mail "smtp.gmail.com"

Estas en el tema de Mandar Mail "smtp.gmail.com" en el foro de ASPX (.net) en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 16/03/2010, 08:37
 
Fecha de Ingreso: enero-2010
Mensajes: 10
Antigüedad: 14 años, 2 meses
Puntos: 0
Mandar Mail "smtp.gmail.com"

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
  #2 (permalink)  
Antiguo 16/03/2010, 09:36
 
Fecha de Ingreso: enero-2010
Mensajes: 10
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Mandar Mail "smtp.gmail.com"

En este ejemplo se ve mas claro,

será porque el puerto esta bloqueado o algo asi

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()

'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("[email protected]")

'To is a collection of MailAddress types
MyMailMessage.To.Add("[email protected]")
MyMailMessage.Subject = "GMail Test"
MyMailMessage.Body = "This is the test text for Gmail email"

'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("[email protected]", "password")
SMTPServer.EnableSsl = True

Try
SMTPServer.Send(MyMailMessage)
Response.Write("Email Sent")
Catch ex As SmtpException
Response.Write(ex.Message)
Response.Write(ex.StackTrace)
Response.Write(ex.StatusCode)
End Try

End Sub

Etiquetas: mail, mandar, aspx
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:14.