This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes sending emil with spring mail abstact layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "sending emil with spring mail abstact layer" Watch "sending emil with spring mail abstact layer" New topic

sending emil with spring mail abstact layer

madhuri akhi

Joined: Sep 18, 2006
Posts: 24
Hi to all
In my application i done, the email send to another. has done normal java program
but i need sping mail abstract.Is it possible through spring mail or not?
if it is possible give me some guidence
L zhong

Joined: Oct 31, 2006
Posts: 4
Yes, it can be done, pls refer to the reference below:
madhuri akhi

Joined: Sep 18, 2006
Posts: 24
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

Avinash Rawana
Ranch Hand

Joined: Feb 22, 2006
Posts: 31
On what line?

--------------<br />Avinash A. Ramana<br />NYIT Student<br /><a href="" target="_blank" rel="nofollow"></a><br />
I agree. Here's the link:
subject: sending emil with spring mail abstact layer
It's not a secret anymore!