package examples;
import javax.mail.*;
import javax.mail.internet.*;
public class SimpleDelivery {
public static void main(String args[]) throws Exception {
MimeMessage mm = new MimeMessage((Session)null);
mm.setText("hello\nworld\n");
java.util.Properties p = new java.util.Properties();
p.put("mail.store.maildir.autocreatedir", "true");
Session session = Session.getDefaultInstance(p);
Store store = session.getStore(new URLName("maildir:///tmp/Maildir"));
Folder inbox = store.getFolder("INBOX");
inbox.appendMessages(new Message[]{mm});
}
}
|
package examples;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.log4j.*;
public class simpleread {
private static Logger log = Logger.getLogger(simpleread.class);
public static void main(String args[])
throws Exception
{
//set up the Logger
BasicConfigurator.configure();
Session session = Session.getInstance(new Properties());
//url examples
String user = "zhukov"; //well this is my home :) you should enter your name here
String absolute_url = "maildir:/home/"+user+"/Maildir";
String absolute_url2 = "maildir:////home/"+user+"/Maildir";
String relative_url = "maildir:///testhome/Maildir";
String url = absolute_url;
Store store = session.getStore(new URLName(url));
store.connect(); //useless with Maildir but included here for consistency
Folder inbox = store.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message m = inbox.getMessage(1);
m.writeTo(System.out);
System.out.println("subject of this message: " + m.getSubject());
m.writeTo(System.out);
}
}
|
package examples;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.log4j.*;
public class deliver
{
private static Logger log = Logger.getLogger(deliver.class);
public static void main(String argv[])
throws Exception
{
BasicConfigurator.configure();
String maildirpath = "///Maildir/";
if ( argv.length == 0 ) {
System.err.println("usage: deliver filename [maildirpath]");
System.exit(1);
} else if ( argv.length >= 2 ) {
if ( argv[1].startsWith("/") )
maildirpath = argv[1];
else
maildirpath = "///" + argv[1];
}
log.info("Delivering " + argv[0] + " to " + maildirpath);
Properties props = new Properties();
//the following specifies whether to create maildirpath if it is not existant
//if not specified then autocreatedir is false
props.put("mail.store.maildir.autocreatedir", "true");
Session session = Session.getInstance(props, null);
session.setDebug(true);
Store store = session.getStore(new URLName("maildir:"+maildirpath));
Folder inbox = store.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
MimeMessage mm = new MimeMessage(session, new FileInputStream(argv[0]));
inbox.appendMessages(new Message[]{(Message)mm});
}
}
|
| © Alexander Zhukov - 2002 |