<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個人學習日記
    主站蜘蛛池模板: 亚洲线精品一区二区三区| 大学生美女毛片免费视频| 亚洲精品人成电影网| 91成人在线免费观看| 国产在线播放免费| 三上悠亚电影全集免费| 国产男女猛烈无遮挡免费视频网站 | 免费视频成人国产精品网站| 在线观看www日本免费网站| 亚洲另类无码一区二区三区| 国产亚洲精品无码专区| 亚洲毛片免费观看| 一区二区三区免费高清视频| 亚洲精品熟女国产| 久久精品国产亚洲一区二区三区| 30岁的女人韩剧免费观看| 亚洲AV无码片一区二区三区 | 亚洲免费视频在线观看| 免费看又爽又黄禁片视频1000| 亚洲欧洲视频在线观看| 免费午夜爽爽爽WWW视频十八禁| 亚洲日本天堂在线| 国产AV无码专区亚洲AVJULIA | 亚洲高清无码专区视频| 99爱在线精品免费观看| 成av免费大片黄在线观看| 亚洲高清一区二区三区| 亚洲性天天干天天摸| 美女被免费视频网站a| 亚洲视频中文字幕在线| 亚洲一区无码精品色| 成人毛片免费观看视频在线| 亚洲人成色99999在线观看| 亚洲AV无码成人精品区在线观看 | 亚洲人成网国产最新在线| 亚洲国产精品无码久久一区二区| 免费一级毛片清高播放| 欧洲黑大粗无码免费| 老司机午夜精品视频在线观看免费 | 亚洲码国产精品高潮在线| 亚洲av成人一区二区三区在线观看 |