I'm not knocking sun.SMTP package because it was easy. But, I like something
with a little more guarantee that it will be around for awhile. So I took the time to
get by
the quirks of JavaMail. A list-server that I wrote for the AS400 included 3 classes.
CheckMail, SendMail, and ListSubscribers. The user's demand was to allow
attachments.
So, if anyone is interested I included a few code <snips> that shows a little
about how I handled multipart. The SendMail class was mostly made up of
a lot of setxxxx's and getxxxx's.
<CheckMail snip>
String subSCT = contentType.substring(0,contentType.indexOf(";"));
sm.setContentType(subSCT);
if(subSCT.toLowerCase().equals("text/plain"))
{
handlePlain(msgs[i], sm);
}
if(subSCT.toLowerCase().equals("multipart/mixed"))
{
handleMime(msgs[i], sm);
}
msgs[i].setFlag(Flags.Flag.DELETED, true);
</CheckMail snip>
<CheckMail snip>
public void handleMime(Message msgM, SendMail sndM) throws MessagingException,
IOException
{
String strContentType;
strContentType = msgM.getContentType();
DataHandler dh = msgM.getDataHandler();
DataSource ds = dh.getDataSource();
recipientAddress = msgM.getAllRecipients();
sndM.setSubject(msgM.getSubject());
sndM.setMimeDataSource(ds);
sndM.sendItMime(sndM.prepareMimeMessage());
msgM.setFlag(Flags.Flag.DELETED, true);
}
</CheckMail snip>
<SendMail snip>
public void setMimeDataSource(DataSource ds_)
{
mimeDataSource = ds_;
}
</SendMail snip>
<SendMail snip>
public MimeMessage prepareMimeMessage() throws MessagingException
{
try
{
MimeMultipart mmp = new MimeMultipart(mimeDataSource);
MimeMessage msg = new MimeMessage(session);
msg.setHeader("Java-Mailer", "AS400 JavaMail");
msg.setSentDate(new Date());
msg.setFrom(fromAddress);
msg.setRecipients(Message.RecipientType.TO,staticToAddress);
msg.setReplyTo(replyToAddress);
msg.addRecipients(Message.RecipientType.BCC,toAddress);
msg.setSubject(subject);
msg.setContent(mmp);
return(msg);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return(null);
}
</SendMail snip>
<SendMail snip>
public void sendItMime(MimeMessage msg)
{
try
{
Transport.send(msg);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
</SendMail snip>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html