Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.44 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Spring 3.0 SimpleMailMessage support
  2. @Service("mailService")
  3.     public class MailService {
  4.  
  5.         @Autowired
  6.         private MailSender mailSender;
  7.         @Autowired
  8.         private SimpleMailMessage alertMailMessage;
  9.  
  10.         public void sendMail(String from, String to, String subject, String body) {
  11.  
  12.             SimpleMailMessage message = new SimpleMailMessage();
  13.  
  14.             message.setFrom(from);
  15.             message.setTo(to);
  16.             message.setSubject(subject);
  17.             message.setText(body);
  18.             mailSender.send(message);
  19.  
  20.         }
  21.        
  22. <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  23.             <property name="host" value="smtp.gmail.com"/>
  24.             <property name="port" value="25"/>
  25.             <property name="username" value="xxx@gmail.com"/>
  26.             <property name="password" value="xxxx"/>
  27.             <property name="javaMailProperties">
  28.                 <props>
  29.                     <!-- Use SMTP transport protocol -->
  30.                     <prop key="mail.transport.protocol">smtp</prop>
  31.                     <!-- Use SMTP-AUTH to authenticate to SMTP server -->
  32.                     <prop key="mail.smtp.auth">true</prop>
  33.                     <!-- Use TLS to encrypt communication with SMTP server -->
  34.                     <prop key="mail.smtp.starttls.enable">true</prop>
  35.                     <prop key="mail.debug">true</prop>
  36.                 </props>
  37.             </property>
  38.         </bean>