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

Digging deeper

In some cases examining only the message properties might provide sufficient evidence of a bounced message. Depending on your particular requirements, however, you may want to extract the offending email address for further processing. We'll look a little deeper at our failure notice sent by our example SMTP server for additional evidence.

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();

         string offendingEmail = ""; // stores the offending email address, if any.
         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...
// message part(0) = response message from server string msgLine = ""; StringReader sr = new StringReader(message.GetPart(0).GetBody()); while ((msgLine = sr.ReadLine()) != null) { EmailAddress eAddr = new EmailAddress(msgLine); // if a valid email address is found... if (eAddr.Valid) { offendingEmail = eAddr.Email; Console.WriteLine("*** Offending Email Address\r\n\t" + offendingEmail + "\r\n***"); break; } } sr.Close(); } if (offendingEmail != "") { Console.WriteLine("\tDelete " + offendingEmail + " from database.\r\n"); Console.WriteLine("Deleting suspect message from POP server."); 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."); } } }

Here we extract the offending email address from the first part of the message, which is the message body of the response email sent from our example SMTP server. Since the message body contains the offending email address on a separate line, it is a simple matter to validate each line as a properly formed email address. If found, then the email address can be removed from a database and the email message removed from the server. Figure 2 illustrates this process.


Conclusion

As you can see from this example, we can parse email messages for those that meet much stricter bounce criteria. Email Factory for .NET exposes additional classes and methods, such as MimeHeaderAttr and GetAttachments() that can aid in parsing bounced email messages. To see what else Email Factory for .NET has to offer Download a FREE 30 day Email Factory for .NET Evaluation.


Page 1  Page 2  Page 3