使用VB接收pop3信箱的郵件

取自http://www.example-code.com/vb/vbReadEmail.asp

在使用前~

先下載這檔~~然後安裝
http://www.example-code.com/downloads/ReadEmail2.zip

安裝後會在C:\Program Files\Chilkat Software Inc\Chilkat Mail ActiveX裡面~

加入參考(Add reference)
加入他的DLL檔~~然後

底下是程式碼
--------------------------------------------------------------------------

Imports CHILKATMAILLib2

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailman As New ChilkatMailMan2

' Any string argument automatically begins the 30-day trial.
Dim success As Integer
success = mailman.UnlockComponent("30-day trial")
If (success <> 1) Then
MsgBox("Component unlock failed")
Exit Sub
End If

' Set the POP3 server's hostname
mailman.MailHost = MAILHOST

' Set the POP3 login/password.
mailman.PopUsername = MAILUSERNAME
mailman.PopPassword = MAILPASSWORD

Dim bundle As ChilkatEmailBundle2
' Copy the all email from the user's POP3 mailbox
' into a bundle object. The email remains on the server.
bundle = mailman.CopyMail()

If (bundle Is Nothing) Then
MsgBox(mailman.LastErrorText)
Exit Sub
End If

Dim i As Integer
Dim email As ChilkatEmail2
For i = 0 To bundle.MessageCount - 1
email = bundle.GetEmail(i)
Text1.Text = Text1.Text & email.From & vbCrLf
Text1.Text = Text1.Text & email.Subject & vbCrLf & vbCrLf
Text1.Text = Text1.Text & email.Body & vbCrLf & vbCrLf
'InsertToDB(email.From, email.Subject, email.Body)
Next

End Sub
End Class

沒有留言: