vljc2004
Sep 12th, 2007, 08:12 PM
Hi, im try send mail with spring but show this:
org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is java.lang.NullPointerException
I create the next class:
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
public class Mail {
private String to;
private String from;
private String content;
public String SendMail(String to,String from,String content) throws AddressException, MessagingException{
Properties correo= new Properties();
correo.setProperty("mail.smtp.host","smtp.gmail.com");
correo.setProperty("mail.smtp.starttls.enbale", "true");
correo.setProperty("mail.smtp.port", "587");
correo.setProperty("mail.smtp.user", "hi@gmail.com");
correo.setProperty("mail.smtp.auth", "true");
Session sesion=Session.getDefaultInstance(correo);
sesion.setDebug(true);
MimeMessage mensaje= new MimeMessage(sesion);
mensaje.setFrom(new InternetAddress(from));
mensaje.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
mensaje.setSubject("Hi");
mensaje.setText("Mensajito con Java Mail<br>" + "<b>de</b> los <i>buenos</i>." + "poque si","html");
Transport t= sesion.getTransport("smtp");
t.connect(null,"hi@gmail.com","1234");
t.sendMessage(mensaje,mensaje.getAllRecipients());
t.close();
return null;
}
}
And SendMailController this:
public class SendMailController implements Controller {
private Mail mail;
public ModelAndView handleRequest(HttpServletRequest resp,
HttpServletResponse arg1) throws Exception {
// TODO Auto-generated method stub
String from=resp.getParameter("from");
String to=resp.getParameter("to");
String content=resp.getParameter("content");
mail.SendMail(to, from, content);
Map date= new HashMap();
dates.put("from_k", from);
date.put("to_k", to);
date.put("content_k", content);
return new ModelAndView("test.jsp","d",date);
}
}
:confused::confused::confused:
when it enters line " mail.SendMail(to, from, content); " break and show error.
On my application not this mapping the class Mail.
Thanks!.
org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is java.lang.NullPointerException
I create the next class:
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
public class Mail {
private String to;
private String from;
private String content;
public String SendMail(String to,String from,String content) throws AddressException, MessagingException{
Properties correo= new Properties();
correo.setProperty("mail.smtp.host","smtp.gmail.com");
correo.setProperty("mail.smtp.starttls.enbale", "true");
correo.setProperty("mail.smtp.port", "587");
correo.setProperty("mail.smtp.user", "hi@gmail.com");
correo.setProperty("mail.smtp.auth", "true");
Session sesion=Session.getDefaultInstance(correo);
sesion.setDebug(true);
MimeMessage mensaje= new MimeMessage(sesion);
mensaje.setFrom(new InternetAddress(from));
mensaje.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
mensaje.setSubject("Hi");
mensaje.setText("Mensajito con Java Mail<br>" + "<b>de</b> los <i>buenos</i>." + "poque si","html");
Transport t= sesion.getTransport("smtp");
t.connect(null,"hi@gmail.com","1234");
t.sendMessage(mensaje,mensaje.getAllRecipients());
t.close();
return null;
}
}
And SendMailController this:
public class SendMailController implements Controller {
private Mail mail;
public ModelAndView handleRequest(HttpServletRequest resp,
HttpServletResponse arg1) throws Exception {
// TODO Auto-generated method stub
String from=resp.getParameter("from");
String to=resp.getParameter("to");
String content=resp.getParameter("content");
mail.SendMail(to, from, content);
Map date= new HashMap();
dates.put("from_k", from);
date.put("to_k", to);
date.put("content_k", content);
return new ModelAndView("test.jsp","d",date);
}
}
:confused::confused::confused:
when it enters line " mail.SendMail(to, from, content); " break and show error.
On my application not this mapping the class Mail.
Thanks!.