貝貝爸爸的程序人生

          關注Seam、BPM
          posts - 23, comments - 10, trackbacks - 0, articles - 32
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
          首先,需要配置mail-service.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- $Id: mail-service.xml 62350 2007-04-15 16:50:12Z dimitris@jboss.org $ -->
          <server>

            
          <!-- ==================================================================== -->
            
          <!-- Mail Connection Factory                                              -->
            
          <!-- ==================================================================== -->

            
          <mbean code="org.jboss.mail.MailService"
                   name
          ="jboss:service=Mail">
              
          <attribute name="JNDIName">java:/Mail</attribute>
              
          <attribute name="User">bpm</attribute>
              
          <attribute name="Password">*****</attribute>
              
          <attribute name="Configuration">
                
          <!-- A test configuration -->
                
          <configuration>
                  
          <!-- Change to your mail server prototocol -->
                  
          <property name="mail.store.protocol" value="pop3"/>
                  
          <property name="mail.transport.protocol" value="smtp"/>

                  
          <!-- Change to the user who will receive mail  -->
                  
          <property name="mail.user" value="bpm"/>
                  
          <property name="mail.smtp.auth" value="true"/>

                  
          <!-- Change to the mail server  -->
                  
          <property name="mail.pop3.host" value="**pop3服務器地址**"/>

                  
          <!-- Change to the SMTP gateway server -->
                  
          <property name="mail.smtp.host" value="***smtp服務器地址***"/>
                  
                  
          <!-- The mail server port -->
                  
          <property name="mail.smtp.port" value="25"/>
                  
                  
          <!-- Change to the address mail will be from  -->
                  
          <property name="mail.from" value="bpm@eontime.com.cn"/>

                  
          <!-- Enable debugging output from the javamail classes -->
                  
          <property name="mail.debug" value="false"/>
                
          </configuration>
              
          </attribute>
              
          <depends>jboss:service=Naming</depends>
            
          </mbean>

          </server>

          其次新建一個jsp頁面mail2.jsp,作為測試
          <%@page contentType="text/html"%>
          <%@ page import="javax.mail.*,javax.mail.internet.*, javax.activation.*, javax.naming.InitialContext" %> 
          <h3>Test JbsssMail DB</h3> 
          <%
          String toAddress
          =request.getParameter("MailTo");
          String fromAddress
          =request.getParameter("MailFrom");
          String subject
          =request.getParameter("MailSubject");
          String content
          =request.getParameter("MailContent");
          InitialContext ctx 
          = new InitialContext(); 
          Session sessions 
          = (Session) ctx.lookup("java:/Mail");
          if(toAddress!=null &&!toAddress.equals("")){ 
          try{
           MimeMessage msg 
          = new MimeMessage(sessions);
           msg.setFrom(
          new InternetAddress(fromAddress));
           msg.setRecipients(javax.mail.Message.RecipientType.TO,toAddress);
           msg.setSubject(subject);
           msg.setSentDate(
          new java.util.Date());
           Multipart multipt 
          = new MimeMultipart();
           MimeBodyPart msgbody 
          = new MimeBodyPart();
           msgbody.setContent(content,
          "text/plain");
           multipt.addBodyPart(msgbody);
           msg.setContent(multipt);
           Transport.send(msg);
           System.out.println(
          "SendMail OK!");
          }
          catch(MessagingException e)
          {
           e.printStackTrace();
          }
          }
          %> 
          <HTML>
          <BODY BGCOLOR="white">
          <form METHOD="POST" ACTION="mail2.jsp">
           
          <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">
              
          <tr>
                
          <td width="150"><div align="left">From :</small></td>
                
          <td width="324"><input TYPE="TEXT" name="MailFrom" value=""></td>
              
          </tr>
              
          <tr>
                
          <td width="150"><div align="left">To :</small></td>
                
          <td width="324"><input TYPE="TEXT" name="MailTo" value=""></td>
              
          </tr>
              
          <tr>
                
          <td width="150"><div align="left">Subject :</small></td>
                
          <td width="324"><input TYPE="TEXT" name="MailSubject" value=""></td>
              
          </tr>
              
          <tr>
                
          <td width="150"><div align="left">Content :</small></td>
                
          <td width="324"><TEXTAREA cols=50 name="MailContent" rows=8></TEXTAREA></td>
              
          </tr>
              
          <tr>
                
          <td></td>
                
          <td colspan="2" width="474"><input TYPE="Submit"></td>
              
          </tr>
           
          </table>
          </form>
          </BODY>
          </HTML>

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 眉山市| 崇州市| 南丹县| 广州市| 塘沽区| 三江| 汕头市| 金坛市| 齐齐哈尔市| 东丰县| 象山县| 集贤县| 蚌埠市| 航空| 东源县| 祁东县| 天台县| 临泽县| 沂水县| 邯郸市| 丰顺县| 贵南县| 巢湖市| 万安县| 沙坪坝区| 土默特右旗| 西乡县| 铜山县| 冷水江市| 鄂伦春自治旗| 西吉县| 体育| 介休市| 黎城县| 上虞市| 浦江县| 井陉县| 定安县| 康定县| 鸡西市| 蒲城县|