Reputation:
i am developing a website for a company, they need to extract the mail content like from_address , subject , some contents(mob_no,place etc) from the mail inbox and are displayed in the site(grid view). i tried to connect to gmail with Pop3 the code is as follows
the code i used is:
Imports OpenPop.Pop3
Imports OpenPop.Mime
Protected Sub Read_Emails(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pop3Client As Pop3Client
If (Session("Pop3Client") Is Nothing) Then
pop3Client = New Pop3Client
pop3Client.Connect("pop.gmail.com", 110, False)
pop3Client.Authenticate("[email protected]", "trustme")
Session("Pop3Client") = pop3Client
Else
pop3Client = CType(Session("Pop3Client"), Pop3Client)
MsgBox(pop3Client)
End If
Dim count As Integer = pop3Client.GetMessageCount
Dim dtMessages As DataTable = New DataTable
dtMessages.Columns.Add("MessageNumber")
dtMessages.Columns.Add("From")
dtMessages.Columns.Add("Subject")
dtMessages.Columns.Add("DateSent")
Dim counter As Integer = 0
Dim i As Integer = count
Do While (i >= 1)
Dim message As Message = pop3Client.GetMessage(i)
dtMessages.Rows.Add()
dtMessages.Rows((dtMessages.Rows.Count - 1))("MessageNumber") = i
dtMessages.Rows((dtMessages.Rows.Count - 1))("From") = message.Headers.From.Address
dtMessages.Rows((dtMessages.Rows.Count - 1))("Subject") = message.Headers.Subject
dtMessages.Rows((dtMessages.Rows.Count - 1))("DateSent") = message.Headers.DateSent
counter = counter + 1
i = i - 1
If counter = 5 Then
Exit Do
End If
Loop
gvEmails.DataSource = dtMessages
gvEmails.DataBind()
End Sub
but the problem is that: it will result in error that "Server not found"
by referencing https://stackoverflow.com/users/1750602/khaksar-weqar answer i got connected with the gmail inbox, extracted some content with the above code. now i want to extract the body content as text to my asp text box, is their any possibility for this? positive response are appreciated.
Upvotes: 2
Views: 826
Reputation: 425
Just change bellow portion of your code:
pop3Client.Connect("pop.gmail.com", 110, False)
pop3Client.Authenticate("[email protected]", "trustme")
Into :
pop3Client.Connect("pop.gmail.com", 995, True)
pop3Client.Authenticate("[email protected]", "trustme", AuthenticationMethod.UsernameAndPassword)
Upvotes: 2