|
-
Jun 6th, 2010, 04:12 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Chilkat emails
Hey,
ON Chilkat they have this piece of code
Code:
TextBox1.Text = ""
' Create a mailman object for reading email.
Dim mailman As New Chilkat.MailMan()
' Any string passed to UnlockComponent automatically begins a 30-day trial.
Dim success As Boolean
success = mailman.UnlockComponent("*code*")
If (success <> True) Then
MsgBox(mailman.LastErrorText)
Exit Sub
End If
' Set our POP3 hostname, login and password
mailman.MailHost = "pop.gmail.com"
mailman.PopUsername = "*mail*"
mailman.PopPassword = "*password*"
' Connecting via SSL is possible by adding these lines:
mailman.PopSsl = True
' Set the POP3 port to 995, the standard MS Exchange Server SSL POP3 port.
mailman.MailPort = 995
' Set our filter to only return PayPal payment notification emails.
'mailman.Filter = "Subject like ""*Notification of Payment Received*"""
' Use GetAllHeaders to fetch each email header and the 1st N lines of
' the body from a POP3 server.
' Note: Attachment information will not be available. This is a shortfall
' of the POP3 protocol because attachment information is not included
' in POP3 headers. An entire POP3 email must be read in order to get complete
' attachment information.
Dim bundle As Chilkat.EmailBundle = mailman.GetAllHeaders(2) ' Get 2 body lines...
If bundle Is Nothing Then
MessageBox.Show(mailman.LastErrorText)
Return
End If
Dim i As Integer
Dim n As Integer = bundle.MessageCount
MsgBox(bundle.MessageCount)
For i = 0 To n - 1
Dim email As Chilkat.Email = bundle.GetEmail(i)
TextBox1.Text = TextBox1.Text + email.From + ControlChars.Cr + ControlChars.Lf
TextBox1.Text = TextBox1.Text + email.Subject + ControlChars.Cr + ControlChars.Lf
ListBox1.Items.Add(email.Subject)
Next i
All of the emails end up in the same textbox.
Is there a way to store the emails in a file or in the memory so when I clikc on the subject in a listbox, it appears in the textbox?
I was thinking of usnig arrays, but then I'd probably use the formatting (new lines etc).
-
Jun 6th, 2010, 04:51 AM
#2
Thread Starter
Addicted Member
Re: Chilkat emails
Oka,y sorted it out.
The solution is to use IMAP and store the emails as text files
Code:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim imap As New Chilkat.Imap()
Dim success As Boolean
' Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("yourcode")
If (success <> True) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
imap.Port = 993
' Connect to an IMAP server.
success = imap.Connect("imap.gmail.com")
If (success <> True) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
' Login
success = imap.Login("[email protected]", "yourpassword")
If (success <> True) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
' Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
If (success <> True) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
Dim messageSet As Chilkat.MessageSet
' We can choose to fetch UIDs or sequence numbers.
Dim fetchUids As Boolean
fetchUids = True
' Get the message IDs of all the emails in the mailbox
messageSet = imap.Search("ALL", fetchUids)
If (messageSet Is Nothing) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
' Fetch the emails into a bundle object:
Dim bundle As Chilkat.EmailBundle
bundle = imap.FetchBundle(messageSet)
If (bundle Is Nothing) Then
MsgBox(imap.LastErrorText)
Exit Sub
End If
' Loop over the bundle and display the FROM and SUBJECT of each.
Dim i As Integer
For i = 0 To bundle.MessageCount - 1
Dim email As Chilkat.Email
email = bundle.GetEmail(i)
TextBox1.Text = TextBox1.Text & email.From & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & email.Subject & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & "--" & vbCrLf
TextBox1.Refresh()
ListBox1.Items.Add(email.Subject)
RichTextBox1.Text = email.GetPlainTextBody
RichTextBox1.SaveFile("D:\email\" & i & ".txt", RichTextBoxStreamType.PlainText)
Next
' Disconnect from the IMAP server.
imap.Disconnect()
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
RichTextBox1.LoadFile("D:\email\" & ListBox1.SelectedIndex & ".txt", RichTextBoxStreamType.PlainText)
End Sub
-
Aug 7th, 2010, 03:27 PM
#3
New Member
Re: [RESOLVED] Chilkat emails
Hi, you may do it a litle simpler than that, you can just use str() methode in a listview like this:
vb Code:
Dim str(8) As String Dim itm As ListViewItem For i = 0 To bundle.MessageCount - 1 str(0) = email.From str(1) = email.Subject str(2) = email.EmailDate itm = New ListViewItem(str) mailList.Items.Add(itm)
-
Dec 21st, 2010, 04:38 AM
#4
New Member
Re: [RESOLVED] Chilkat emails
What is this 30 day trial thing in the code does that mean? Do you have to buy this stuff?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|