Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javamail/applet

Reply
Thread Tools

javamail/applet

 
 
anonymous@coolgroups.com
Guest
Posts: n/a
 
      05-26-2004
can i use javamail stuff from an applet
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      05-26-2004
On Wed, 26 May 2004 19:15:26 GMT, wrote:

> can i use javamail stuff from an applet


depends
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-26-2004
On Wed, 26 May 2004 19:15:26 GMT, wrote or
quoted :

>can i use javamail stuff from an applet


Yes but.

You can only talk to the mailserver if it lives at the same IP that
served the Applet.

You are willing to wait for the fat Javamail jar to download. Best to
do this with Java Web Start.


see http://mindprod.com/jgloss/javawebstart.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
mromarkhan@rogers.com
Guest
Posts: n/a
 
      06-06-2004



Peace be unto you.

Q: Can I use JavaMail in applets?
http://java.sun.com/products/javamail/FAQ.html#applets



A jnlp solution:
On server
mailapi.jar
activation.jar
pop3.jar
SignedMail.jar
Support.jnlp
Mail.jnlp
Activation.jnlp

Inside SignedMail.jar
MailSorter.java
TableSorter.java - Sun tutorial file

-- Mail.jnlp
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://members.rogers.com/mromarkhan"
href="Mail.jnlp">
<information>
<title>Read Pop Email</title>
<vendor>Omar</vendor>
<homepage href="pop.html"/>
<description>Read Pop Email</description>
<description kind="short">Read Pop Email</description>
<icon href="pop.jpg"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.4"/>
<jar href="SignedMail.jar"/>
<extension name="JavaMail Api" href="Support.jnlp"/>
<extension name="Activation Api" href="Activation.jnlp"/>
</resources>
<application-desc main-class="MailTableSorter"/>
</jnlp>
-- Mail.jnlp

-- Support.jnlp
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://members.rogers.com/mromarkhan" href="Support.jnlp">
<information>
<title>JavaMail</title>
<vendor>Sun Microsystems, Inc.</vendor>
</information>
<resources>
<jar href="pop3.jar" download="eager" />
<jar href="mailapi.jar" download="eager" />
</resources>
<component-desc/>
</jnlp>
-- Support.jnlp

-- Activation.jnlp
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://members.rogers.com/mromarkhan" href="Activation.jnlp">
<information>
<title>Activation API</title>
<vendor>Sun Microsystems, Inc.</vendor>
</information>
<resources>
<jar href="activation.jar" download="eager" />
</resources>
<component-desc/>
</jnlp>
-- Activation.jnlp


-- MailTableSorter.java
<code>
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
import java.awt.event.*;
import java.awt.*;
import javax.mail.Flags.*;
import javax.swing.table.*;

public class MailTableSorter extends JPanel implements ActionListener
{
JPopupMenu popup;
JTable table;
static Folder inboxFolder;

String hostName = "";
String userName = "";
String passWord = "";


class PopupListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}

public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}

private void maybeShowPopup(MouseEvent e)
{
int selectedRows [] = table.getSelectedRows();
if (selectedRows.length == 0)
{
return;
}
if (e.isPopupTrigger())
{
popup.show(e.getComponent(),e.getX(), e.getY());
}
}
}

public void actionPerformed(ActionEvent e)
{
int selectedRows [] = table.getSelectedRows();
if (selectedRows.length == 0)
{
return;
}
try
{
for(int i = 0;i< selectedRows.length;i++)
{
Message message = (Message)table.getModel().getValueAt(selectedRows[i],3);
if (message.isSet(Flags.Flag.DELETED))
{
message.setFlag(Flags.Flag.DELETED,false);
}
else
{
message.setFlag(Flags.Flag.DELETED,true);
}

}
}
catch(Exception ex)
{
System.err.println(ex);
}
}

public MailTableSorter()
{
super(new GridLayout(1,0));

hostName = JOptionPane.showInputDialog("Please enter your pop address ex. pop");
userName = JOptionPane.showInputDialog("Your user name");
passWord = JOptionPane.showInputDialog("Your password");


//...where the GUI is constructed:
//Create the popup menu.
popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Delete selection");
menuItem.addActionListener(this);
popup.add(menuItem);

TableSorter sorter = new TableSorter(new MyTableModel());
table = new JTable(sorter);
MouseListener popupListener = new PopupListener();
table.addMouseListener(popupListener);

sorter.setTableHeader(table.getTableHeader());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
//Set up tool tips for column headers.
table.getTableHeader().setToolTipText(
"Click to specify sorting; Control-Click to specify secondary sorting");
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}

class MyTableModel extends AbstractTableModel
{
private Object[][] data=null;

public MyTableModel()
{
Message messages[]=null;
try
{
// Get system properties
Properties props = System.getProperties();
// Get session
Session session = Session.getDefaultInstance(props,null); //java.lang.NullPointerException
Store store = session.getStore(new URLName("pop3://"+userName+":"+passWord+"@"+hostName+":110/INBOX"));
// Get folder
store.connect();
inboxFolder = store.getFolder("INBOX");
inboxFolder.open(Folder.READ_WRITE);//Exception in thread "main" java.lang.IllegalStateException: Folder not open
messages= inboxFolder.getMessages();
data = new Object[messages.length][4];
for(int i = 0; i < messages.length;i++)
{
data[i][0] = messages[i].getSubject();
Address[] addresses = messages[i].getFrom();
data[i][1] = ((InternetAddress)addresses[0]).getPersonal();
data[i][2] = messages[i].getSentDate();
data[i][3] = messages[i];
}
}
catch(Exception e)
{
System.exit(1);
}


for (int i=0; i < messages.length; i++)
{
System.out.print(" row " + i + ":");
for (int j=0; j < 3; j++)
{
System.out.print(" " + data[i][j]);
}
System.out.println();
}
}



private String[] columnNames =
{
"Subject",
"From",
"Date"
};


public int getColumnCount()
{
return columnNames.length;
}

public int getRowCount()
{
return data.length;
}

public String getColumnName(int col)
{
return columnNames[col];
}

public Object getValueAt(int row, int col)
{
return data[row][col];
}


}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI()
{
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("MailTableSorter");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
//Create and set up the content pane.
MailTableSorter newContentPane = new MailTableSorter();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent wE)
{
try
{
inboxFolder.close(true);
}
catch(Exception e)
{
System.err.println(e.toString());
}
}
}
);
frame.setVisible(true);
}

public static void main(String[] args)
{
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI();
}
});
}
}
</code>


-- Building
javac -classpath ".;C:\downloads\javamail-1_3_1\javamail-1.3.1\lib\pop3.jar;C:\downloads\javamail-1_3_1\javamail-1.3.1\lib\mailapi.jar;C:\downloads\jaf-1_0_2-upd\jaf-1.0.2\activation.jar" MailTableSorter.java

jar -cvf Omar.jar *.class
REM enter your info
keytool -genkey -alias omarFiles -keypass omarkey -keystore omarstore -storepass omarstore
REM pass phrase for keystoremarstore pass for omarFilesmarkey
jarsigner -keystore omarstore -signedjar SignedMail.jar Omar.jar omarFiles




I had a problem as defined by
"If Java Web Start prints out a bad installation error message:"
http://java.sun.com/products/javaweb...e.html#trouble

I fixed it by
Error message stating
c:\Program Files\Java\j2re1.5.0\bin\javaw.exe
is non existant.
Which is true.

I clicked on the shortcut in C:\Java Web Start.

The Java Web Start Application Manager appears.
I went to file menu then preferences sub menu.
I clicked the Java tab.
I noticed the runtime versions pointed to non existing files.
I removed them, then I clicked find and went to my java bin directory.
It found it.
Everything was super afterwards.

-- References
http://java.sun.com/developer/techni...art/index.html
By Raghavan N. Srinivas

http://java.sun.com/docs/books/tutor...ign/step3.html
By Mary Dageforde

TableSorter.java
http://java.sun.com/docs/books/tutor...e.html#sorting

//JAR resources in JNLP file are not signed by same certificate
How do I use JAR files that are signed by different certificates?
http://java.sun.com/products/javawebstart/faq.html#72

How to Use Popup menus
http://java.sun.com/docs/books/tutor...ents/menu.html

Have a Good Day.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-06-2004
On Sun, 06 Jun 2004 01:09:48 GMT, wrote or
quoted :

>Q: Can I use JavaMail in applets?
>http://java.sun.com/products/javamail/FAQ.html#applets


yes but. The problem is the entire Javamail jar would be downloaded
each time, and you could only talk to the mailserver on the same
machine from which the applet was loaded. You are better off with JWS
so that the Javamail jar gets downloaded only once.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments