Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Read and Forward POP3 EmailRead a POP3 mailbox, removes any XML file attachments, and forwards the email to another email account.
' The mailman object is used for receiving (POP3) ' and sending (SMTP) email. Dim mailman As New Chilkat.MailMan() ' Any string argument automatically begins the 30-day trial. Dim success As Boolean success = mailman.UnlockComponent("30-day trial") If (success <> true) Then MsgBox("Component unlock failed") Exit Sub End If ' Set the POP3 server's hostname mailman.MailHost = "mail.chilkatsoft.com" ' Set the POP3 login/password. mailman.PopUsername = "matt@chilkatsoft.com" mailman.PopPassword = "*myPassword2*" Dim bundle As Chilkat.EmailBundle ' 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 ' Set the SMTP hostname for sending. mailman.SmtpHost = "smtp.comcast.net" ' Set your SmtpUsername/Password for authentication if necessary. ' This example assumes that SMTP authentication is not needed. Dim i As Long Dim email As Chilkat.Email For i = 0 To bundle.MessageCount - 1 email = bundle.GetEmail(i) TextBox1.Text = TextBox1.Text & email.From & vbCrLf TextBox1.Refresh() TextBox1.Text = TextBox1.Text & email.Subject _ & vbCrLf & vbCrLf TextBox1.Refresh() ' Loop over the attachment filenames. Drop any ' ending in .xml Dim numAttach As Long Dim j As Long numAttach = email.NumAttachments For j = 0 To numAttach - 1 Dim fname As String fname = email.GetAttachmentFilename(j) TextBox1.Text = TextBox1.Text & fname & vbCrLf TextBox1.Refresh() ' If the fname ends in .xml, we would call ' email.DropSingleAttachment(j); ' You would also want to decrement numAttach ' and decrement j before the next loop iteration. Next ' Clear the To and CC email recipients. email.ClearTo() email.ClearCC() ' Add the recipient to receive the forwarded email: email.AddTo("Chilkat Support","support@chilkatsoft.com") ' Send the email success = mailman.SendEmail(email) If (success <> true) Then TextBox1.Text = TextBox1.Text & mailman.LastErrorText & vbCrLf TextBox1.Refresh() Exit While End If Next ' Remove the emails in bundle from the POP3 server. success = mailman.DeleteBundle(bundle) If (success <> true) Then TextBox1.Text = TextBox1.Text & mailman.LastErrorText & vbCrLf TextBox1.Refresh() End If |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.