aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes sending mail hangs - no exception thrown, mail not sent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "sending mail hangs - no exception thrown, mail not sent" Watch "sending mail hangs - no exception thrown, mail not sent" New topic
Author

sending mail hangs - no exception thrown, mail not sent

chinomso ikwuagwu
Greenhorn

Joined: Mar 28, 2006
Posts: 11
The code below is taken from a servlet in my web application on netbeans 6.1
The netbeans IDE pretty much handles all thats needed for sending email from java files
=====================CODE==============================
package bc.servlets;

import java.io.*;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.naming.NamingException;
import javax.servlet.*;
import javax.servlet.http.*;

/**
*
* @author nonso
*/
public class Send extends HttpServlet {
@Resource(name = "mail/myYahoomailSession")
private Session mailmyYahoomailSession;

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Send.processRequest, //////////////////// ENTERED ////////////////////");
try {
this.sendMail("chinomsoikwuagwu@yahoo.com", "Mail From TestWebApp", "Congrats on your success");
System.out.println("Send.processRequest, //////////////////// SUCCESS ////////////////////");
}catch(javax.naming.NamingException e) {
e.printStackTrace();
}catch(javax.mail.MessagingException e1) {
e1.printStackTrace();
}
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Send</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Servlet Send at " + request.getContextPath () + "</h2>");
out.println("<b>Thanks for signing up. A message has been sent to your mail box</b>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}


// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}

private void sendMail(String email, String subject, String body) throws NamingException, MessagingException {
MimeMessage message = new MimeMessage(mailmyYahoomailSession);
System.out.println("Send.sendMail, message:" + message);
message.setSubject(subject);
System.out.println("Send.sendMail, SUBJECT SET");
message.setRecipients(javax.mail.Message.RecipientType.TO, javax.mail.internet.InternetAddress.parse(email, false));
System.out.println("Send.sendMail, RECIPIENTS SET");
message.setText(body);
System.out.println("Send.sendMail, BODY SET");
javax.mail.Transport.send(message);
System.out.println("Send.sendMail, MESSAGE SENT");
}
// </editor-fold>
}
================================CODE===========================

The output message below is given.
The mail is never sent, even after 30minutes of waiting.
Would love to know why?

Application server startup complete.
deployed with moduleid = mail
DEBUG: JavaMail version 1.4.1
DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_06\jre\lib\javamail.providers
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_06\jre\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_06\jre\lib\javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_06\jre\lib\javamail.address.map (The system cannot find the file specified)
Send.processRequest, //////////////////// ENTERED ////////////////////
Send.sendMail, message:javax.mail.internet.MimeMessage@1f92ac0
Send.sendMail, SUBJECT SET
Send.sendMail, RECIPIENTS SET
Send.sendMail, BODY SET
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you tried enabling JavaMail's debugging? You can see the SMTP conversation, which is helpful.


The netbeans IDE pretty much handles all thats needed for sending email from java files

What does it do? How do you define the server details etc. ?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
chinomso ikwuagwu
Greenhorn

Joined: Mar 28, 2006
Posts: 11
Thanks for the tip on catching other exception

I CAUGHT THE FOLLOWING EXCEPTION WHEN I USED HOST NAME mail.yahoo.com

javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <chinomsoikwuagwu@yahoo.com>: Sender address rejected: Access denied
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at bc.servlets.Send.sendMail(Send.java:113)
at bc.servlets.Send.processRequest(Send.java:38)
at bc.servlets.Send.doGet(Send.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <chinomsoikwuagwu@yahoo.com>: Sender address rejected: Access denied
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1192)
... 39 more


I CAUGHT THE FOLLOWING WHEN I USED 'smtp.gmail.com'

Send.processRequest, //////////////////// STARTED ////////////////////
Send.sendMail, message:javax.mail.internet.MimeMessage@8dcd41
Send.sendMail, SUBJECT SET
Send.sendMail, RECIPIENTS SET
Send.sendMail, BODY SET
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <mikemayas@gmail.com>: Sender address rejected: Access denied
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at bc.servlets.Send.sendMail1(Send.java:126)
at bc.servlets.Send.processRequest(Send.java:49)
at bc.servlets.Send.doGet(Send.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <mikemayas@gmail.com>: Sender address rejected: Access denied
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1192)
... 39 more
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41798
    
  62
I don't see anything in your code that deals with password authentication. Most email servers require that these days, and they'll definitely do so if the connection doesn't originate from within the same network (like if you're trying to use Yahoo or Google).


Ping & DNS - my free Android networking tools app
chinomso ikwuagwu
Greenhorn

Joined: Mar 28, 2006
Posts: 11
how do i implement password authentication considering that the netbeans IDE auto generated most of the above code???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41798
    
  62
Nothing prevents you adding the code manually, right? This tutorial shows how: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending mail hangs - no exception thrown, mail not sent