博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jboss3.0-Tomcat4.03下运用JavaMail发电子邮件. (转)
阅读量:2499 次
发布时间:2019-05-11

本文共 2891 字,大约阅读时间需要 9 分钟。

Jboss3.0-Tomcat4.03下运用JavaMail发电子邮件. (转)[@more@] 

Operator System:  2000 server 2

Application server:  3.0-4.03

:  8.17

:   jdk1.31

  Server    1.3 

首先好Jboss3.0-Tomcat4.03我安装在E:Jboss3.0_Tomcat4.03,打开E:Jboss3.0_Tomcat4.03serverdefaultdeploy目录下的-service.其内容如下

<?xml version="1.0" encoding="UTF-8"?>

 

  archives="mail.jar, activation.jar, mail-plugin.jar"/>

 

  name="jboss:service=Mail">

  :/Mail

  nobody

  word">password

 

 

 

 

 

  domain.com"/>

 

 

  bug" value="false"/>

 

 

 

我用的是的免费,它是要经过SMTP的,所以这里是必填的

 nobody

 password

修改的如下

<?xml version="1.0" encoding="UTF-8"?>

 

  archives="mail.jar, activation.jar, mail-plugin.jar"/>

 

  name="jboss:service=Mail">

  java:/TestJbossMail

  lacklhl//名

  password//密码

 

 

   

   

   

   

   

   

 

 

 

如果要经过Smtp认证的必须有这么样的一句

而在Jboss提供的例子中是没有的,大家必须加上.

其实大家可以根据自己的需要进行修改的,其实SMTP认证的Java代码是这样的.

protected Session getSession()

  {

  Session mailsession=null;

  if(!getPassword().equals("")&&!getUser().equals(""))microsoft-com::office" />

  {

    final PasswordAuthentication pa = new PasswordAuthentication(getUser(), getPassword());

      Authenticator a = new Authenticator() {

      Protected PasswordAuthentication getPasswordAuthentication()

      {

      return pa;

      }

    };

    Properties props = getProperties();

    mailsession = Session.getInstance(props, a);

     }else{

    Properties props = getProperties();

    mailsession = Session.getInstance(props, null);

   }

  return mailsession;

下面我就写一个简单的的测试,收就不做了,(我用的是,在SessionBean,JavaBean中的用法基本是一样的) ,编写.war或.ear包来测试一个简易的做法就是:

1、 在deploy目录下建立sendmail-test.war目录。

2、在sendmail-test.war目录下建立WEB-INF目录,其中有两个文件

jboss-web.xml和web.xml

内容分别是

jboss-web.xml内容是

web.xml内容是

<?xml version="1.0"?>

/P>

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

 

三、在sendmail-test.war目录下建立新文件index.jsp其内容是

.NET.*, javax.activation.*, javax.naming.InitialContext" %>

Test JbsssMail DB

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:/TestJbossMail");

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();

  }

}

%>

RM METHOD="POST" ACTION="index.jsp">

 

 

 

From :

 

 

 

 

To :

 

 

 

 

Subject :

   

 

 

 

Content :

 

 

 

   

 

 

 

一切OK

这只是一个简单的例子,大家可以根据需要进行扩展,例如发Html格式的邮件,带附件的邮件等等

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-959292/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10748419/viewspace-959292/

你可能感兴趣的文章
量化策略回测DualThrust
查看>>
量化策略回测BoolC
查看>>
量化策略回测DCCV2
查看>>
mongodb查询优化
查看>>
五步git操作搞定Github中fork的项目与原作者同步
查看>>
git 删除远程分支
查看>>
删远端分支报错remote refs do not exist或git: refusing to delete the current branch解决方法
查看>>
python multiprocessing遇到Can’t pickle instancemethod问题
查看>>
APP真机测试及发布
查看>>
通知机制 (Notifications)
查看>>
10 Things You Need To Know About Cocoa Auto Layout
查看>>
一个异步网络请求的坑:关于NSURLConnection和NSRunLoopCommonModes
查看>>
iOS 如何放大按钮点击热区
查看>>
ios设备唯一标识获取策略
查看>>
获取推送通知的DeviceToken
查看>>
Could not find a storyboard named 'Main' in bundle NSBundle
查看>>
CocoaPods安装和使用教程
查看>>
Beginning Auto Layout Tutorial
查看>>
block使用小结、在arc中使用block、如何防止循环引用
查看>>
iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
查看>>