貝貝爸爸的程序人生

          關(guān)注Seam、BPM
          posts - 23, comments - 10, trackbacks - 0, articles - 32
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
          首先,需要配置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服務(wù)器地址**"/>

                  
          <!-- Change to the SMTP gateway server -->
                  
          <property name="mail.smtp.host" value="***smtp服務(wù)器地址***"/>
                  
                  
          <!-- 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>

          其次新建一個(gè)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>

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 彭州市| 神农架林区| 永川市| 文水县| 宝鸡市| 湖南省| 红河县| 宝丰县| 云霄县| 广昌县| 尼玛县| 彩票| 都昌县| 蓝山县| 溧阳市| 宝山区| 康定县| 阳山县| 贵阳市| 枣阳市| 永泰县| 大荔县| 永平县| 日照市| 南汇区| 和顺县| 荥经县| 永城市| 沈阳市| 镇原县| 富源县| 宜春市| 栾城县| 汕尾市| 旅游| 铅山县| 内乡县| 隆昌县| 鄂温| 泗阳县| 大渡口区|