Java and .NET components, FTP, TELNET, SMTP, POP3, IMAP, HTTP, SSH
Home Search Knowledge Base Support

Support

Click here for access to live sales support.

For technical support please submit a ticket to the Help Desk.

 

Java and .NET Help

iPod shuffle offer

For a limited time get the newly re-designed iPod shuffle free with qualifying purchase.

Click for details.


News

JSCAPE is Hiring
06/27/2008 02:34 PM

JSCAPE Secure FTP Server 4.0 Released
06/20/2008 08:53 AM

Secure iNet Factory 8.0.3 Released
06/11/2008 08:20 AM

Community forums launched
06/08/2008 06:09 AM

Secure iNet Factory 8.0 Released
04/04/2008 02:24 PM

Updates to Email Factory for .NET and Secure iNet Factory
03/29/2008 04:06 PM

more...


Tutorials

Email Validation with Java
04/15/2008 02:04 PM

Sending HTML Based Email Using Java
03/11/2008 02:47 PM

Secure FTP Using Java and FTPS (FTP over SSL)
03/10/2008 04:08 PM

FTP Directory Listing Using Java
03/10/2008 03:57 PM

Sending Email Using Java
03/09/2008 03:43 PM

SSH Using Java
03/09/2008 02:53 PM

more...


Articles

Best Practices for Configuring Your FTP Server
06/03/2008 04:47 PM

What is the difference between passive and active FTP?
05/20/2008 09:27 AM

What is the difference between FTP, FTPS and SFTP?
05/19/2008 04:29 PM

DMZ File Transfer Streaming
03/28/2008 11:57 AM

Phishing looks to FTP to distribute malware
03/13/2008 05:14 PM

Ad Hoc File Transfer Explained
03/13/2008 09:16 AM

more...


Feedback

Request a feature or component

Request a Java or .NET component


 

Parsing Bounced Emails

Page 1  Page 2  Page 3

Setup

We'll begin by creating a new C# console application called EmailExample. In it we'll need to add the Jscape.Email.dll reference and include the following basic structure. See the Email Factory for .NET User Guide for more information about adding a reference to your project.

using System; using System.Collections; using System.IO; using System.Text; using Jscape.Email; namespace EmailExample { public class EmailExample { public EmailExample() { } [STAThread] static void Main() { } } }

Instantiating the Pop class

Email Factory for .NET exposes many properties and methods that allow you to connect to a POP server, trap various events, and retrieve email messages and attachments. Now that we have the basic structure in place, we can begin adding our code to accomplish these tasks.

To create a Pop instance we'll pass the hostname, username, and password as parameters to the constructor. You will need to pass in the appropriate parameters for your server. You can review the API documentation for more information.

using System;
using System.Collections;
using System.IO;
using System.Text;
using Jscape.Email;

namespace EmailExample {

   public class EmailExample {

      public EmailExample(string hostname, string username, string password) {
// ... Instantiate POP3 ... myPop = new Pop(this.hostname, this.username, this.password); // ... Turn on debug mode ... myPop.Debug = true; // ... Override delete messages setting ... myPop.DeleteMessages = false; // ... and subscribe to pop events. myPop.ConnectedEvent += new Pop.ConnectedEventHandler(OnConnected); myPop.DisconnectedEvent += new Pop.DisconnectedEventHandler(OnDisconnected);
} [STAThread] static void Main() { // Ensure that you use proper credentials EmailExample bounced = new EmailExample("hostname", "username", "password"); } public void OnConnected(object sender, PopConnectedEventArgs e) { Console.WriteLine("Connected to {0}", e.Host); } public void OnDisconnected(object sender, PopDisconnectedEventArgs e) { if (myPop.IsConnected()) { myPop.Disconnect(); } Console.WriteLine("Disconnected."); } } }

Retrieving and parsing messages

Now that we have a completed structure we can start processing the email messages on our example POP server. We'll begin by parsing the email message using the simplest form -- Check the message properties for suspect values.

using System;
using System.Collections;
using System.IO;
using System.Text;
using Jscape.Email;

namespace EmailExample {

   public class EmailExample {

      public EmailExample(string hostname, string username, string password) {
         // ... Instantiate POP3 ...
         myPop = new Pop(this.hostname, this.username, this.password);
         // ... Turn on debug mode ...
         myPop.Debug = true;
         // ... Override delete messages setting ...
         myPop.DeleteMessages = false;
         // ... and Subscribe to pop events.
         myPop.ConnectedEvent += new Pop.ConnectedEventHandler(OnConnected);
         myPop.DisconnectedEvent += new Pop.DisconnectedEventHandler(OnDisconnected);
// connect to pop server myPop.Connect(); int mc = 0; // message counter used to delete offending message after processing. // iterate through all email messages IEnumerator e = myPop.GetMessages(); while(e.MoveNext()) { mc++; // message indexes are 1-based. EmailMessage message = (EmailMessage)e.Current; // first test message properties for clues. if ( (message.From.ToLower().IndexOf("mailer-daemon") > 0) || (message.From.ToLower().IndexOf("mail delivery subsystem") > 0) || (message.Subject.ToLower().IndexOf("returned") > 0) ) { // this is a suspect message... Console.WriteLine("Suspect message found. Deleting."); myPop.DeleteMessage(mc); } } // your server may require a slight delay in order to respond. Thread.Sleep(100); // disconnect from server myPop.Disconnect();
} [STAThread] static void Main() { // Ensure that you use proper credentials EmailExample bounced = new EmailExample("hostname", "username", "password"); } public void OnConnected(object sender, PopConnectedEventArgs e) { Console.WriteLine("Connected to {0}", e.Host); } public void OnDisconnected(object sender, PopDisconnectedEventArgs e) { if (myPop.IsConnected()) { myPop.Disconnect(); } Console.WriteLine("Disconnected."); } } }

Only the message properties were checked to match our example message. If the properties match then we can remove the email message from the server. Figure 1 illustrates this process.


Page 1  Page 2  Page 3