Wednesday, April 29, 2009

Send attachment through java mail

For run this code you should download mail.jar
http://mirrors.ibiblio.org/pub/mirrors/maven/ant/jars/ant-javamail-1.6.jar

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class Main
{
public static void main (String args[]) throws Exception
{
String host = "mail.xyz.com"; //Host name should be some mail host name
String from = "sounak@xyz.com"; // form address
String to = "sounak@xyz.com"; // to address
String fileAttachment = "d:\\sqljdbc.jar"; // file path
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getInstance(props, null);
// Define message MimeMessage message = new MimeMessage(session); message.setFrom( new InternetAddress(from));
message.addRecipient( Message.RecipientType.TO, new InternetAddress(to)); message.setSubject( "Hello JavaMail Attachment");
// create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
messageBodyPart.setText("Hi");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttachment); messageBodyPart.setDataHandler( new DataHandler(source)); messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send( message );
}
}

Monday, April 27, 2009

Java script browser detection and movable div

//browser detection

var agt=navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

//movable div
function initToolTips()
{
if(document.getElementById)
{
toolTipSTYLE = document.getElementById("toolTipLayer").style;
}
if(is_ie is_nav6up)
{
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
document.onmousemove = moveToMousePos;
}
}
function moveToMousePos(e)
{
if(!is_ie)
{ x = e.pageX; y = e.pageY; }
else
{ x = event.x + document.body.scrollLeft; y = event.y + document.body.scrollTop;
}
toolTipSTYLE.left = x + offsetX+'px';
toolTipSTYLE.top = y + offsetY+'px';
return true;
}
function hide()
{ if(is_nav4) toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
}
function show()
{ toolTip(s);
}
function toolTip(msg, fg, bg)
{
if(toolTip.arguments.length < 1)
// if no arguments are passed then hide the tootip
{ if(is_nav4)
toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
} else
// show { var content = msg; if(is_nav4)
{ toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible"; }
else if(is_ie is_nav6up)
{ document.getElementById("toolTipLayer").innerHTML = content; toolTipSTYLE.display='block'; }
}
}

////Above java script is to create the moveable div
//add this code into your page

// add this to any control to your page
onmouseout="hide();" onmouseover="initToolTips();doImage('image name or text');show();

Logout Funda

response.addHeader("Cache-Control", "max-age = 0, s-maxage = 0,must-revalidate, proxy-revalidate, no-cache, no-store ");
response.addHeader("Pragma", "no-cache");


Place the code in the head of the every page.Log out function work properly.