Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Unfortunately we could not use the notification event in KM for various reasons. Most notably, we were not notifying upon an action on a KM object. We needed something simple, flexible, and fast.

Here's what I came up with:

import java.io.*;
import java.util.*;
import sun.net.smtp.SmtpClient;

public class SMTP extends Thread{
     public String whoto;
     public String username;
     public String whofrom;
/* our constructor */
public SMTP(String whoto, String username, String whofrom){
          this.whoto = whoto;
          this.username = username;
          this.whofrom = whofrom;
     }
/* run method for multithreading */
     public void run(){
          doGet();
     }
     public void doGet( )
                           {
                       
     try {

          SmtpClient smtp =
                           new SmtpClient("yourdomain.com");
         
          smtp.from(whofrom);
         
          //Pass the email address of the recipient of the
          // message to the next method.
          smtp.to(whoto);

       //Get an output stream for the message
          PrintStream msg = smtp.startMessage();
         
          //Write the message header in the output stream.
          msg.println("To: "+whoto);
          msg.println("Subject: New Email");
          msg.println();
         
          //Write the text of the message in the output
          // stream
          msg.println("An event has happened.");
          msg.println("Please do not reply to this automated email.");

       //Close the stream and send the message
          smtp.closeServer();
         

     }catch( Exception e ) {
       e.printStackTrace();
     }
  }
}

This method is called by:

IUser loggedOnUser = (IUser) request.getUser().getUser()
SMTP mysmtp = new SMTP(whoto, loggedOnUser.getName(), whofrom);
mysmtp.start(); // starts the thread
2 Comments