Monday, June 30, 2008

Download Email from a POP3 Server

textBox1.Text = ""

' Create a mailman object for reading email.
Dim mailman As New Chilkat.MailMan()

' Any string argument automatically begins the 30-day trial.
mailman.UnlockComponent("30-day trial")

' Set our POP3 hostname, login and password
mailman.MailHost = "mail.chilkatsoft.com"
mailman.PopUsername = "login"
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;
' Download email from the POP3 server by calling TransferMail
Dim bundle As Chilkat.EmailBundle
bundle = mailman.TransferMail()
If bundle Is Nothing Then
MessageBox.Show(mailman.LastErrorText)
Return
End If

Dim i As Integer
Dim n As Integer = 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
textBox1.Text = textBox1.Text + email.Body + ControlChars.Cr + ControlChars.Lf + "****" + ControlChars.Cr + ControlChars.Lf
Next i

No comments: