Hello,
I am trying to send a simple mail from one user to another using a
servlet. I have been trying this from yday and I am definitely missing
something. I went through several examples and the examples that came
along with the javamail api but can't seem to find whats wrong.
I am getting the following exception:
Problem sending mesage: javax.mail.NoSuchProviderException: No
provider for Address type: rfc822
I am sure the to, from addresses are right. The host name which is the
smtp server is also right since I have done something similar using
Active Server Pages and it works fine.
Any help would be greatly appreciated.
Thanks.
The code is:
....
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String msgText = "This is a message body. Here's the second line.";
String from = "[EMAIL PROTECTED]";
String to = "[EMAIL PROTECTED]";
String host = "EMAIL_XYZ";
boolean debug = true;
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("JavaMail APIs Test");
msg.setSentDate(new Date());
msg.setDisposition("text/html");
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(msgText);
Transport.send(msg);
out.println("Message sent successfully");
} catch (MessagingException mex) {
out.println("\n--Exception handling in msgsendsample.java");
out.println("Problem sending mesage: " + mex);
}
..
_________________________________________________________
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