aspose file tools*
The moose likes Servlets and the fly likes about the exception from the mail servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "about the exception from the mail servlet" Watch "about the exception from the mail servlet" New topic
Author

about the exception from the mail servlet

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This is with reference to the previous post:
Frank:I used the code that you had posted in an earlier message.Still I get the exception NoSuchProviderException:no provider for address type rfc822.
Can anybody help??
*****************************************************
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.net.InetAddress;
import javax.mail.*;
import javax.mail.internet.*;

public class MailServlet extends HttpServlet
{
static final String FROM = "ABC";
static final String TO = "xxx@xxx.xxx.com";
private static final String smtpHost = "xxx.xxx.com";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String msgText = "A Body";
boolean debug = false;
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(properties, null);
session.setDebug(debug);
try
{
Message msg = new MimeMessage(session);
InternetAddress from = new InternetAddress(FROM);
msg.setFrom(from);
InternetAddress [] address = {new InternetAddress(TO)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test Mail");
msg.setSentDate(new Date());
msg.setHeader("Test", "servlets");
msg.setContent(msgText, "text/plain");
msg.saveChanges();

Transport.send(msg);
}
catch (MessagingException mex)
{
mex.printStackTrace();
}
}
}
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The most common starting problem with Java Mail is actually a classpath issue. Are you sure that both the mail.jar and activation.jar files are in your classpath?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Frank:
Yes both the jar files are in the classpath,also I added pop3.jar too.The server has been restarted so that the new path is taken by the server.That part is pretty clear.Still I got the earlier exception.I tried another construct:
Transport trans = new com.sun.mail.smtp.SMTPTransport(session, new URLName(urlname));
where urlname is:
String urlname = "smtp://"+ smtpHost +":"+ port;
Now I didnt get the Exception but I didnt get the mail either.
I used smtpHost in form xxx.xxx.com and port is a number.So finally I have smtp://xxx.xxx.com:25
I have no idea how to make this work.Help!!!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Wierd. It works quite happily for me. Which server and Java version are you using?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Frank:
I am using weblogic server 5.1.0 and I am using java 2 with jdk1.2.2.The code was written in textpad.Someone mentioned that there can be access problem with the server,so I am looking into that.Any other suggestions??
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I've never used or configured Weblogic, but I can say that my mail code works OK in most other servlet containers I've tried.
Sorry I couldn't be more help.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try to use following codes:
......
Transport transport=session.getTransport("smtp");
transport.connect(smtpHost, user, password);
transport.sendMessage(msg, address);
......
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Unfortunately,I am still working on the problem.Looks like my code is alright but there is some security issues.I downloaded the javawebserver2.0 to test the code and now I have the exception:
java.security.AccessControlException: access denied (java.net.SocketPermission xxx.xxx.com resolve) at java.security.AccessControlContext.checkPermission
What kind of security permission is it asking for?After all I am trying to send an email to myself.
jhonghua:I tried the code that you posted and I have the same exception.
FYI:my code was not developed on visual age or any IDE,its written from scratch in textpad.
fordsm
Greenhorn

Joined: May 22, 2001
Posts: 2
The problem lies with WebLogic. put mail.jar & activation.jar in the WebLogic Classpath BEFORE weblogicaux.jar and it should work.
see also: http://www.jguru.com/faq/view.jsp?EID=122151
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"kant28, zhonghua, fordsm",
Some of these posts are really old, but you should all be aware that the Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name.
If you haven't already done so, please log in with a new name which meets the requirements.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about the exception from the mail servlet