This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Problem at sending  email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Problem at sending  email" Watch "Problem at sending  email" New topic

Problem at sending email

madhuri akhi

Joined: Sep 18, 2006
Posts: 24
Please if it know the solution replay to me
this is my context.html

<bean id="Connectmail" class="com.nanna.ConnectMail">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>formbean</value></property>
<property name="commandClass"><value>com.nanna.FormBean</value></property>
<property name="mailSender"><ref bean="mailSender"/></property>
<property name="message"><ref bean="mailMessage"/></property>
<property name="formView"><value>Home</value></property>

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value=""/>

<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value=""/>
public class ConnectMail extends SimpleFormController{
private MailSender mailSender;
private SimpleMailMessage message;
String to_user="";
String content="";

public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws ServletException,Exception {

//to_user ="user";
//content = "content";
Map myModel = new HashMap();
myModel.put("to_user", to_user);
myModel.put("content", content);
boolean temp=sendMail(to_user,content);
return new ModelAndView("show");

public boolean sendMail(final String to_user,final String content) throws MessagingException {

MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws MessagingException {
new InternetAddress(to_user));
mimeMessage.setFrom(new InternetAddress(""));

mailSender.send((SimpleMailMessage) preparator);
catch(MailException ex) {
//log it and go on

return true;
public MailSender getMailSender() {
return mailSender;

public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;

public SimpleMailMessage getMessage() {
return message;

public void setMessage(SimpleMailMessage message) {
this.message = message;

at the time of running am getting java.lang.ClassCastException

if it know how can it solve

I agree. Here's the link:
subject: Problem at sending email
jQuery in Action, 3rd edition