Skip to Content

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
To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Senthil Murugan
    Hi Jason,

    Good one. Unfortunately, I’m surprised to see  none has added comment to this basic good stuff.

    Though this is late, but a better one for you!

    Regards
    Senthil

    (0) 
  2. Yantong Wang
    In your solution the content in the email is plain text. Is it possible to add a hyperlink in the content that recipient can click and open it.

    Thanks for reply.

    Kind regards.

    Wang

    (0) 

Leave a Reply