I'm using JavaMail, because I tried a couple of smtpClasses that were around but none
of them handled iso-8859-1, JavaMail is actually easy to use when you know how to,
this is a static method that I use in my own class library in a class called
MailTools, all you need to do is to import the javax.mail package:
public static boolean sendSimpleMail(String to, String from, String cc, String bcc,
String subject, String body, String replyTo, String smtpServer)
throws MailerException
{
Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false));
msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc,
false));
msg.setSubject(subject, "iso-8859-1");
msg.setSentDate(new Date());
msg.setReplyTo(InternetAddress.parse(replyTo));
msg.setText(body, "iso-8859-1");
msg.setHeader("X-Mailer", "nation mailer 2.0");
msg.saveChanges();
Transport.send(msg);
return true;
} catch (MessagingException mex) {
// some error handling
return false;
}
}
this is very simple and creates a perfectly good email message, with all the
appropriate headers.
Placing two .jar files in the classpath is a very simple task and only needs to be
done once.
-Henric
----- Original Message -----
From: Jason Hunter <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 17, 1999 8:48 PM
Subject: Re: Servlet using sun.net.smtp.SmtpClient?
> This is going to sound a little harsh, but IMHO it is
> irresponsible for a respected author to encourage Java
> developers to learn and use bad habits.
Well, I wasn't a respected author at the time. :-)
I really hoped to use JavaMail, but the code using JavaMail was such
that even sending a simple message brought in all this complexity, and
I felt if I used that code I should at least quickly describe what
every line was doing. That would have gotten long. I also pictured
the tech support nightmare of people having problems installing two
.jar files just to send an email. It wasn't worth it.
I looked for free third party packages next. At the time I couldn't
find many, and no good ones. There has been some development in this
area since more than a year ago when I wrote that section. Today
maybe there's a good alternative. Every one I saw back then was just
as unsupported as Sun's SmtpClient code, was less widely available,
and was more likely to be removed from its web site than SmtpClient
was to be removed from the JDK.
I decided that if I gave the book a big warning and pointed out this
was only an example of what could be done, I could sleep at night. :-)
-jh-
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
___________________________________________________________________________
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
___________________________________________________________________________
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