使用JBoss配置发送邮件
2008-05-20 16:26
489 查看
[align=center]使用JBoss配置发送邮件[/align]
Author: liuxiaohua
现在需要利用jmail 发邮件,本想自己写发邮件,但查看jboss资料,发现其已mail service 只需要做相应的配置既可配置文档位置 {jboss4.2_home}/server/default/deploy/mail-service.xml
原文
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/Mail</attribute>
<attribute name="User">nobody</attribute>
<attribute name="Password">password</attribute>
<attribute name="Configuration">
<!-- Test -->
<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="nobody"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.nosuchhost.nosuchdomain.com"/>
<!-- Change to the address mail will be from -->
<property name="mail.from" value="nobody@nosuchhost.nosuchdomain.com"/>
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="false"/>
</configuration>
</attribute>
</mbean>
根据自己的发送邮箱的设置,修改相应参数,如下(参考)
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/tourMail</attribute><!-- JNDI name 具体看相关资料 名 -->
<attribute name="User">88bye</attribute><!-- 邮箱用户名 -->
<attribute name="Password">******</attribute><!-- 邮箱密码 -->
<attribute name="Configuration">
<!-- Test -->
<configuration>
<!-- smtp check -->
<property name="mail.smtp.auth" value="true"/><!-- 这个很重要,如果邮箱服务器要smtp 验证一定要加该属性才能通过验证 -->
<!-- Change to your mail server prototocol -->
<property name="mail.store.protocol" value="pop3"/><!-- 接受协议 默认pop3-->
<property name="mail.transport.protocol" value="smtp"/><!-- 传输协议 默认smtp -->
<!-- Change to the user who will receive mail -->
<property name="mail.user" value="Admin"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.126.com"/><!-- pop3 服务器 -->
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.126.com"/><!-- smtp 服务器 -->
<!-- Change to the address mail will be from -->
<property name="mail.from" value="email@126.com"/><!-- 邮箱地址 ,与上面的用户名一致 -->
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="true"/><!-- 是否打印信息 -->
</configuration>
</attribute>
</mbean>
配置就好了,就要看怎么应用了,一下是个测试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:/tourMail");
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="mail.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>
Author: liuxiaohua
现在需要利用jmail 发邮件,本想自己写发邮件,但查看jboss资料,发现其已mail service 只需要做相应的配置既可配置文档位置 {jboss4.2_home}/server/default/deploy/mail-service.xml
原文
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/Mail</attribute>
<attribute name="User">nobody</attribute>
<attribute name="Password">password</attribute>
<attribute name="Configuration">
<!-- Test -->
<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="nobody"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.nosuchhost.nosuchdomain.com"/>
<!-- Change to the address mail will be from -->
<property name="mail.from" value="nobody@nosuchhost.nosuchdomain.com"/>
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="false"/>
</configuration>
</attribute>
</mbean>
根据自己的发送邮箱的设置,修改相应参数,如下(参考)
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/tourMail</attribute><!-- JNDI name 具体看相关资料 名 -->
<attribute name="User">88bye</attribute><!-- 邮箱用户名 -->
<attribute name="Password">******</attribute><!-- 邮箱密码 -->
<attribute name="Configuration">
<!-- Test -->
<configuration>
<!-- smtp check -->
<property name="mail.smtp.auth" value="true"/><!-- 这个很重要,如果邮箱服务器要smtp 验证一定要加该属性才能通过验证 -->
<!-- Change to your mail server prototocol -->
<property name="mail.store.protocol" value="pop3"/><!-- 接受协议 默认pop3-->
<property name="mail.transport.protocol" value="smtp"/><!-- 传输协议 默认smtp -->
<!-- Change to the user who will receive mail -->
<property name="mail.user" value="Admin"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.126.com"/><!-- pop3 服务器 -->
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.126.com"/><!-- smtp 服务器 -->
<!-- Change to the address mail will be from -->
<property name="mail.from" value="email@126.com"/><!-- 邮箱地址 ,与上面的用户名一致 -->
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="true"/><!-- 是否打印信息 -->
</configuration>
</attribute>
</mbean>
配置就好了,就要看怎么应用了,一下是个测试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:/tourMail");
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="mail.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>
相关文章推荐
- Jboss4中使用配置发送邮件
- 使用JBoss配置发送邮件
- 使用JBoss配置发送邮件
- Linux使用外部服务器发送邮件配置手册
- Imail 邮件服务器的SMTP配置与 .NET 下使用 System.Net.SmtpClient 发送邮件
- C#发送邮件(使用Gmail或自己配置的SMTP)
- 使用SQLServer2000 发送邮件详细配置过程
- CentOS6.5_64位系统下安装配置postfix邮件系统 启用并配置SMTP在第三方上边使用发送邮件
- Laravel5使用QQ邮箱发送邮件配置
- Postfix邮件服务器的原理和postfix + dovecot配置,使用Thunderbird发送邮件和SMTP认证
- 使用PHP邮件库swiftmailer发送邮件时,QQ,163邮箱的配置
- phplist及phpmailer(组合使用)通过gmail发送邮件的配置方法
- ubuntu下使用mutt和msmtp发送邮件的简单配置
- 使用SQLServer2000 发送邮件详细配置过程
- 基于Windows Azure 搭建基于SharePoint 2010 Intranet、Extranet、Internet (4): 配置传出邮件服务: 使用 outlook.com 发送邮件通知
- 使用SQLServer2000 发送邮件详细配置过程
- ThinkPHP3.2中配置使用PHPMiler发送邮件最新整理
- 使用.net的SmtpMail发送邮件及本机SMTP的简单配置
- 服务器使用阿里云安装的CentOS7, 配置外部邮件服务器,使用mail命令发送邮件