This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes mail API Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "mail API Problem" Watch "mail API Problem" New topic
Author

mail API Problem

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
Its urgent... i'm not able to send mail.

package com.test;

import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

/**
* Servlet Class
*
* @web.servlet name="mail"
* display-name="Name for mail"
* description="Description for mail"
* @web.servlet-mapping url-pattern="/mail"
* @web.servlet-init-param name="A parameter"
* value="A value"
*/
public class mail extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException {

String smtpHost = "smtpout.travelguru.com";
String from = req.getParameter("form");
String to = req.getParameter("to");
String msg = req.getParameter("message");
// Get system properties
Properties props = System.getProperties();

PrintWriter out=resp.getWriter();

// Setup mail server
props.put(smtpHost, "True");

// Get session
Session session =
Session.getDefaultInstance(props, null);

// Define message
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setText(msg);

// Send message
Transport.send(message);
}catch(Exception e){
e.printStackTrace();
out.println(e.fillInStackTrace());
}
}
}

Stack Trace

5:24:37,648 ERROR [STDERR] java.lang.NullPointerException
15:24:37,648 ERROR [STDERR] at javax.mail.internet.InternetAddress.parse(InternetAddress.java:569)
15:24:37,648 ERROR [STDERR] at javax.mail.internet.InternetAddress.parse(InternetAddress.java:529)
15:24:37,648 ERROR [STDERR] at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:65)
15:24:37,648 ERROR [STDERR] at com.test.mail.doGet(mail.java:48)
15:24:37,648 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
15:24:37,648 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
15:24:37,648 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
15:24:37,648 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
15:24:37,648 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
15:24:37,648 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
15:24:37,648 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
15:24:37,648 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
15:24:37,648 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
15:24:37,648 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
15:24:37,648 ERROR [STDERR] at java.lang.Thread.run(Unknown Source)


Jigar Naik


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Welcome to JavaRanch.

You're not setting the host to connect to. There should be a line like:


By the way, most questions are urgent, so you might do well to EaseUp.


Ping & DNS - updated with new look and Ping home screen widget
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

String from = request.getParameter("form");

The stack trace is there to help you.

Dave
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
Originally posted by David O'Meara:
String from = request.getParameter("form");

The stack trace is there to help you.

Dave


thanks... but what about the other errors...

16:13:12,919 ERROR [STDERR] at javax.mail.Transport.send0(Transport.java:218)
16:13:12,919 ERROR [STDERR] at javax.mail.Transport.send(Transport.java:80)
16:13:12,919 ERROR [STDERR] at com.test.mail.doGet(mail.java:55)
16:13:12,919 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
16:13:12,919 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
16:13:12,919 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
16:13:12,919 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
16:13:12,919 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
16:13:12,919 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
16:13:12,919 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
16:13:12,919 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
16:13:12,950 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
16:13:12,950 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
16:13:12,950 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
16:13:12,950 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
16:13:12,950 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
16:13:12,950 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
16:13:12,950 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
16:13:12,950 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
16:13:12,950 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
16:13:12,950 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
16:13:12,950 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
16:13:12,950 ERROR [STDERR] at java.lang.Thread.run(Unknown Source)

thay are still there gives me source not found
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
ok... i got it... Thanks a lot. dev
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mail API Problem
 
Similar Threads
simple javamail example getting error
Servlet code in JSP page
mail API Problem
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. i20sm7448258wff.17
how to send mail using gmail server