title: Sending email by Spring via Google ()
body: <p>The code below works well<br/></p>
  
  <p>But, my question is how can set the 'javaMailProperties' programaticaly ?
  Because I would like to set ssl/tsl from the code. I could not access these properties, I dont know why, thanks for the solution and explanation.</p>
  
  <pre><code>SimpleMailMessage message=(SimpleMailMessage)SpringUtil.getContext().
  getBean("templateMessage");
  
  JavaMailSenderImpl mailSender = (JavaMailSenderImpl)SpringUtil.getContext()
  .getBean("mailSender"); 
  
  mailSender.send(message);
  
  --applicationcontext.xml--
  
  &lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
     &lt;property name="host" value="smtp.gmail.com"/&gt;
     &lt;property name="port" value="587"/&gt;
     &lt;property name="username" value="your gmail address"/&gt;
     &lt;property name="password" value="your password"/&gt;        
  
     &lt;property name="javaMailProperties"&gt;
      &lt;props&gt;
          &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
          &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
      &lt;/props&gt;
  &lt;/property&gt;
  
   &lt;/bean&gt;
  
  &lt;bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage" &gt;
  &lt;property name="from" value="from@gmail.com"/&gt;
      &lt;property name="to" value="to@gmail.com"/&gt;              
      &lt;property name="subject" value="subject"/&gt;
      &lt;property name="text" value="hello"/&gt;               
   &lt;/bean&gt;
  </code></pre>
  
  <p>(I dont want to use javax.mail approach, it was asked)</p>