Wednesday, 23. November 2005
Forwarding Notes Email to Your Phone When Your System Isn't On11/23/2005 11:53 PM
Here's something you can easily modify
Lotus Notes to do (because "Notes email" is just another Notes
application) that you can't easily do w/ other email systems: you can forward
your email using text messaging to your phone if your computer isn't on.
This is great for when you're on vacation and want to make sure you
still get all your important emails, but don't want to log onto your email
periodically to check it.
Safe travel to all and hearty eating for Thanksgiving
Put this Java agent (has to be unrestricted
because it makes network calls) into your mail file as an After Mail Arrives
agent. Modify the hostname with the name of your workstation. Modify
the phonesms field with the email address to send a text message to your
phone (usually your 7 digit number at your cell phone provider). Modify
the comparison of email headers (how you define importance) as appropriate.
The .abstractText() call is commented
out because it fails on my system, but if it works on yours, that's probably
the best thing to use to bring your text message size down.
import lotus.domino.*;
import java.io.*;
import java.net.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
String hostname = "myworkstation";
String phonesms = "xxxxxxxxxx@tmomail.net";
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
boolean fWorkstationRunning = true;
Socket testSocket = null;
try {
testSocket = new Socket(hostname, 135);
} catch (UnknownHostException e) {
} catch (IOException e) {
fWorkstationRunning = false;
}
if (testSocket != null) {
testSocket.close();
}
// handle unprocessed documents
Database db = agentContext.getCurrentDatabase();
DocumentCollection dc = agentContext.getUnprocessedDocuments();
Document doc = dc.getFirstDocument();
while (doc != null) {
String subject = doc.getItemValueString("Subject");
if (doc.hasItem("SMTPOriginator"))
{
String
sender = doc.getItemValueString("SMTPOriginator");
sender
= sender.toLowerCase();
//
see if sender is important
boolean
fImportant = false;
if
((sender.indexOf("@customer1.com") > 0) ||
(sender.indexOf("@customer2.com") > 0))
{
fImportant = true;
}
//
if sender is important and workstation is off, forward to phone
if
(fImportant & !fWorkstationRunning) {
RichTextItem richbody = (RichTextItem) doc.getFirstItem("Body");
String body = richbody.getFormattedText(false, 0, 0);
//String bodysummary = doc.getFirstItem("Body").body.abstractText(200,
true, true);
if (body.length() > 50000) {
body = body.substring(0,
50000);
}
Document maildoc = db.createDocument();
maildoc.replaceItemValue("SendTo", phonesms);
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("From", sender +
"@XXX");
maildoc.replaceItemValue("PRINCIPAL", sender
+ "@XXX");
maildoc.replaceItemValue("Subject", subject);
RichTextItem mailbody = maildoc.createRichTextItem("Body");
mailbody.appendText("From: " + sender);
mailbody.addNewLine(2);
mailbody.appendText(body);
maildoc.send(false);
System.out.println("message '" + subject
+ "' forwarded to SMS at " +
(new java.util.Date()).toString());
}
}
agentContext.updateProcessedDoc(doc);
doc = dc.getNextDocument();
}
} catch(Exception
e) {
e.printStackTrace();
}
}
}