Usuário com melhor resposta
email

Pergunta
-
Respostas
-
1- Possuir conta de email;
2- O servidor de email permitir que a sua aplicação faça uma pesquisa de emails via POP3;
3- Criar um coneção ao servidor usando TcpClient(Servidor,Porta): no gmail é ("pop.gmail.com",995)
4- Efectuar login de utilizador com email e password;
5- Pesquisar email usando no servidor.
O login e a pesquisa de email é feita por meio de comandos enviados ao servidor.
Um exemplo bem básico:
Dim POP3 As TcpClient = Nothing Dim nt As NetworkStream = Nothing Dim slt As SslStream = Nothing Dim rs As StreamReader = Nothing Private Function LoginServidor() As Boolean If Not POP3 Is Nothing AndAlso POP3.Connected Then POP3.Close() Try POP3 = New TcpClient(txtServer.Text, Val(cboPorta.Text)) Catch ex As Exception MsgBox(ex.Message) Return False End Try nt = POP3.GetStream slt = New SslStream(nt) Try slt.AuthenticateAsClient(txtServer.Text) Catch ex As Exception MsgBox(ex.Message) Return False End Try rs = New StreamReader(slt) Dim R As String = rs.ReadLine() 'Descrição do servidor ListBox1.Items.Add(R) R = SendCommand("USER " & txtUser.Text) ListBox1.Items.Add(R) R = SendCommand("PASS " & txtPwd.Text) ListBox1.Items.Add(R) Return True End Function Private Sub LogoutServidor() Dim rs As StreamReader = New StreamReader(slt) Dim R As String = SendCommand("QUIT ") End Sub Private Sub ListarEmails() ListBox1.Items.Clear() ListBox2.Items.Clear() LoginServidor() Dim R As String R = SendCommand("STAT ") 'numero de mensagens ListBox1.Items.Add(R) Dim X() As String = R.Split(" ") ListBox2.Items.Clear() For I As Integer = 1 To Val(X(1)) R = SendCommand("LIST " & I) ListBox2.Items.Add(R) Next End Sub Function SendCommand(ByVal Server_Command As String) As String Server_Command = Server_Command + vbCrLf Dim B() As Byte = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray()) slt.Write(B, 0, B.Length) Return rs.ReadLine() End Function
- Sugerido como Resposta Lucio Rogerio SPBanned segunda-feira, 8 de junho de 2015 20:53
- Marcado como Resposta Cristopher C I_ terça-feira, 9 de junho de 2015 13:17
Todas as Respostas
-
-
1- Possuir conta de email;
2- O servidor de email permitir que a sua aplicação faça uma pesquisa de emails via POP3;
3- Criar um coneção ao servidor usando TcpClient(Servidor,Porta): no gmail é ("pop.gmail.com",995)
4- Efectuar login de utilizador com email e password;
5- Pesquisar email usando no servidor.
O login e a pesquisa de email é feita por meio de comandos enviados ao servidor.
Um exemplo bem básico:
Dim POP3 As TcpClient = Nothing Dim nt As NetworkStream = Nothing Dim slt As SslStream = Nothing Dim rs As StreamReader = Nothing Private Function LoginServidor() As Boolean If Not POP3 Is Nothing AndAlso POP3.Connected Then POP3.Close() Try POP3 = New TcpClient(txtServer.Text, Val(cboPorta.Text)) Catch ex As Exception MsgBox(ex.Message) Return False End Try nt = POP3.GetStream slt = New SslStream(nt) Try slt.AuthenticateAsClient(txtServer.Text) Catch ex As Exception MsgBox(ex.Message) Return False End Try rs = New StreamReader(slt) Dim R As String = rs.ReadLine() 'Descrição do servidor ListBox1.Items.Add(R) R = SendCommand("USER " & txtUser.Text) ListBox1.Items.Add(R) R = SendCommand("PASS " & txtPwd.Text) ListBox1.Items.Add(R) Return True End Function Private Sub LogoutServidor() Dim rs As StreamReader = New StreamReader(slt) Dim R As String = SendCommand("QUIT ") End Sub Private Sub ListarEmails() ListBox1.Items.Clear() ListBox2.Items.Clear() LoginServidor() Dim R As String R = SendCommand("STAT ") 'numero de mensagens ListBox1.Items.Add(R) Dim X() As String = R.Split(" ") ListBox2.Items.Clear() For I As Integer = 1 To Val(X(1)) R = SendCommand("LIST " & I) ListBox2.Items.Add(R) Next End Sub Function SendCommand(ByVal Server_Command As String) As String Server_Command = Server_Command + vbCrLf Dim B() As Byte = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray()) slt.Write(B, 0, B.Length) Return rs.ReadLine() End Function
- Sugerido como Resposta Lucio Rogerio SPBanned segunda-feira, 8 de junho de 2015 20:53
- Marcado como Resposta Cristopher C I_ terça-feira, 9 de junho de 2015 13:17