Author
sending emil with spring mail abstact layer
madhuri akhi
Greenhorn
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
Greenhorn
Joined: Oct 31, 2006
Posts: 4
posted Oct 31, 2006 17:30:00
0
Yes, it can be done, pls refer to the reference below: http://www.springframework.org/docs/reference/mail.html
madhuri akhi
Greenhorn
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> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="64.79.170.116"/> </bean> <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="support@easyuploader.com"/> </bean> ConnectMail.java 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=((FormBean)command).getUserid(); content=((FormBean)command).getContent(); System.out.println("to_user"+to_user); System.out.println("content"+content); //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); System.out.println(temp); 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 { mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress (to_user)); mimeMessage.setFrom(new InternetAddress ("support@easyuploader.com")); mimeMessage.setText(content); } }; try{ mailSender.send((SimpleMailMessage) preparator); } catch(MailException ex) { //log it and go on System.err.println(ex.getMessage()); } 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 from madhuri
Avinash Rawana
Ranch Hand
Joined: Feb 22, 2006
Posts: 31
On what line?
--------------<br />Avinash A. Ramana<br />NYIT Student<br /><a href="http://www.aramana.org" target="_blank" rel="nofollow">http://www.aramana.org</a><br />avinash@styleempire.com
subject: sending emil with spring mail abstact layer