Phil no digo que es un error en tu código, solo pregunto la función de LoginMail pues cuando mandas un gmail ese parámetro no se carga por ningún sitio. Esto ya me lo mandaste otra vez y no me soluciono nada. Voy a revisar todo otra vez.
Imports System.Net.Mail ' Requerido para poder usar el gmail con visual Net
Imports System.Text
Public Class frmCorreo
Private Sub MessageSenderCode()
' Dim Password As String = "123Azerty"
' Dim LoginGMail As String = "azeqwarto" '
[email protected]
Dim LoginGMail As String = "miguelarce1951"
Dim Mail As MailMessage
Dim smtp As SmtpClient
'Dim Expediteur As String
'Dim Destinataire As String
Try
Mail = New MailMessage
Mail.SubjectEncoding = UTF8Encoding.UTF8 ' Forma de codigo del objecto
Mail.BodyEncoding = UTF8Encoding.UTF8 ' Forma de codigo del mensaje
Mail.Subject = txtAsunto.Text ' el objecto del mensaje en un TextBox
Mail.Body = txtCuerpo.Text ' el mensaje en un RichTextBox
smtp = New SmtpClient("smtp.gmail.com") ' servidor SMTP permitido en el ordinador
'Expediteur = "
[email protected]"
Mail.From = New MailAddress(txtEmisor.Text) 'el remitente
'Destinataire = "
[email protected]"
Mail.To.Add(New MailAddress(txtReceptor.Text)) ' el destinatario
smtp.Port = 587
smtp.Credentials = New System.Net.NetworkCredential(LoginGMail, txtPassword.Text) 'LoginGMail y Password estan escribido en las primeras lines de esto codigo
smtp.EnableSsl = True
smtp.Send(Mail) ' Enviar mensaje
Mail.Dispose()
Catch ex As ApplicationException
MessageBox.Show(ex.Message)
Finally
smtp = Nothing
Try
Mail.Dispose()
Catch
End Try
Mail = Nothing
End Try
End Sub
Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnviar.Click
If txtReceptor.Text = Nothing Then
MsgBox("Por favor entre la dirección email")
Exit Sub
End If
Call MessageSenderCode()
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub BtnChequear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChequear.Click
FrmConChk.Show()
End Sub
Private Sub FrmCorreo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblTime.Text = Format(Now, "MMMM d, yyyy h:mm:ss tt")
txtEmisor.Text = "@gmail.com"
txtEmisor.SelectionStart = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblTime.Text = Format(Now, "MMMM d, yyyy h:mm:ss tt")
End Sub
Private Sub TxtEmisor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmisor.KeyPress
Dim ch As Char = e.KeyChar
If ch = Chr(13) Or ch = Chr(9) Then
txtPassword.Focus()
End If
End Sub
Private Sub TxtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
Dim ch As Char = e.KeyChar
If ch = Chr(13) Or ch = Chr(9) Then
txtReceptor.Focus()
End If
End Sub
Private Sub txtReceptor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtReceptor.KeyPress
Dim ch As Char = e.KeyChar
If ch = Chr(13) Or ch = Chr(9) Then
txtAsunto.Focus()
End If
End Sub
Private Sub txtAsunto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAsunto.KeyPress
Dim ch As Char = e.KeyChar
If ch = Chr(13) Or ch = Chr(9) Then
txtCuerpo.Focus()
End If
End Sub
Private Sub txtCuerpo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCuerpo.KeyPress
Dim ch As Char = e.KeyChar
If ch = Chr(13) Or ch = Chr(9) Then
btnEnviar.Focus()
End If
End Sub
End Class
Este es el código adaptado a lo mio. Te mando la Pantalla de la aplicación por si quieres probar en tu ordenador igual que estoy pasando algo por alto.
Un saludo