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

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

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

    直接放代碼上來,經(jīng)過測試成功。使用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 閱讀(702) 評論(0)  編輯  收藏 所屬分類: Struts1Spring個人學(xué)習(xí)日記
    主站蜘蛛池模板: 亚洲香蕉成人AV网站在线观看| 免费激情视频网站| 亚洲中文字幕日产乱码高清app| 精品一区二区三区免费毛片| 免费精品一区二区三区在线观看| 丁香婷婷亚洲六月综合色| 亚洲免费综合色在线视频| 在线观看亚洲AV每日更新无码| 亚洲欧洲免费无码| 亚洲国产综合AV在线观看| 青青青国产色视频在线观看国产亚洲欧洲国产综合 | 一级成人a做片免费| 亚洲精品国精品久久99热| 一个人看的hd免费视频| 国产亚洲精品自在久久| 十八禁无码免费网站| 亚洲精品在线视频观看| 日韩一区二区a片免费观看| 亚洲Av无码国产一区二区| 男人的天堂亚洲一区二区三区| 亚洲精品一卡2卡3卡四卡乱码| 国产美女精品久久久久久久免费| 日韩一级片免费观看| 久久精品国产亚洲综合色| 午夜免费1000部| 亚洲精品美女久久7777777| 亚洲精品久久久www| 久久久久久一品道精品免费看| 亚洲一区二区三区在线网站| 国产aa免费视频| 免费av一区二区三区| 亚洲人成网站色7799| 中文亚洲成a人片在线观看| 1000部禁片黄的免费看| 国产精品亚洲专区无码不卡| 亚洲伊人色欲综合网| 老司机在线免费视频| 农村寡妇一级毛片免费看视频| 久久亚洲国产精品一区二区| 久草视频免费在线| 一区二区三区AV高清免费波多|