<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    直接放代碼上來,經過測試成功。使用gmail來作為測試,因為gmail不是使用25端口,并且需要ssl支持,所以需要聲明這些部分。

    serviceContext-moudle_sendmail.xml:

    <beans>
        <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
          <property name="host" >
         <value>smtp.gmail.com</value>
        </property>
      <property name="javaMailProperties">
     <props>
     <prop key="mail.smtp.auth">true</prop>
       <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
        <prop key="mail.smtp.socketFactory.fallback">false</prop>
     <prop key="mail.smtp.timeout">25000</prop>
     </props>
     </property>
     <property name="port">
            <value>465</value>
            </property>
     <property name="username">
     <value>your_name@gmail.com</value>
     </property>
     <property name="password">
      <value>your_password</value>
     </property>  
     </bean>
       
        <bean id ="enrollmentMailMessage" class="org.springframework.mail.SimpleMailMessage">
        <property name="to">
         <value>abc@21cn.com</value>
        </property>
        <property name="from">
         <value>your_name@gmail.com</value>
        </property>
        <property name="subject">
         <value>spring mail test</value>
        </property>
        </bean>
       
     <bean id="SendMail" class="com.yourcompany.service.SendMailImpl">
     <property name="mailMessage">
         <ref bean="enrollmentMailMessage"/>
        </property>
     <property name="mailSender">
         <ref bean="mailSender"/>
        </property>   
     </bean>
    </beans>

    SendMailAction.java

    public ActionForward execute(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) {
      DynaActionForm sendMailForm = (DynaActionForm) form;// TODO Auto-generated method stub
      String strcontent = sendMailForm.getString("content");
      sendMail.sendmail(strcontent);
      return mapping.findForward("ok");
     }
     private SendMail sendMail;
     public void setSendMail(SendMail dao){
      this.sendMail = dao;  
     }

    SendMail.java

    public interface SendMail {
     public void sendmail(String content);
    }

    SendMailImpl.java

    public class SendMailImpl implements SendMail {
    private MailSender mailSender;
    public void setMailSender(MailSender mailSender){
     this.mailSender = mailSender;
    }
     private SimpleMailMessage mailMessage;
     public void setMailMessage(SimpleMailMessage mailMessage){
      this.mailMessage = mailMessage;
     }

     public void sendmail(String content){
      SimpleMailMessage message = new SimpleMailMessage(this.mailMessage);
      StringBuffer messageText = new StringBuffer();
      messageText.append(content);
      message.setText(messageText.toString());
      mailSender.send(message);
     }
    }


    struts-config.xml

        <form-bean name="sendMailForm" type="org.apache.struts.validator.DynaValidatorForm">
          <form-property name="content" type="java.lang.String" />
        </form-bean>

        <action
          attribute="sendMailForm"
          input="/sendmail/SendMail.jsp"
          name="sendMailForm"
          path="/sendMail"
          scope="request"
          validate="true"
          type="com.yourcompany.struts.action.SendMailAction" >
          <forward name="ok" path="/sendmail/SendMailOk.jsp" />
        </action>

    SendMail.jsp

      <html:form action="/sendMail">
       content : <html:text property="content"/><html:errors property="content"/><br/>
       <html:submit/><html:cancel/>
      </html:form>

    validation.xml

       </form>
         <form name="sendMailForm">
         <field property="content" depends="required">
           <arg key="sendMailForm.content"/>    
           </field>      
       </form>
    posted on 2008-01-14 18:10 lzj520 閱讀(708) 評論(0)  編輯  收藏 所屬分類: Struts1Spring個人學習日記
    主站蜘蛛池模板: 久久经典免费视频| 亚洲视频免费播放| 自拍偷自拍亚洲精品情侣| 久久久久亚洲爆乳少妇无| 亚洲中文字幕无码中文字在线| 亚洲精品白浆高清久久久久久| 亚洲国产精品线在线观看| 无码人妻一区二区三区免费视频 | 大妹子影视剧在线观看全集免费| 中文在线免费不卡视频| 在线永久看片免费的视频| 国产一区二区视频免费| 亚洲天堂中文资源| 国产亚洲精品免费| 91精品国产免费久久久久久青草| 成人免费视频国产| 亚洲福利视频导航| 夜夜爽妓女8888视频免费观看| 国内精品免费麻豆网站91麻豆 | 亚洲另类激情专区小说图片| 亚洲黄色免费观看| jizz18免费视频| 免费永久看黄在线观看app| 亚洲AV无码乱码在线观看富二代| 亚洲国产成人久久精品软件| 99精品免费观看| 亚洲人成人77777网站| 亚洲国产精品视频| 国产亚洲欧美在线观看| 免费无码肉片在线观看| 亚洲精品美女在线观看| 亚洲a一级免费视频| 88av免费观看| 久久久久亚洲精品日久生情 | 久久精品国产亚洲av麻豆色欲 | 亚洲人成网亚洲欧洲无码| 1024免费福利永久观看网站| 亚洲日本在线播放| 亚洲w码欧洲s码免费| 亚洲综合激情另类小说区| 91高清免费国产自产|