使用JBoss配置发送邮件
2011-01-18 16:11
369 查看
现在需要利用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>
原文
<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>
相关文章推荐
- 使用JBoss配置发送邮件
- Jboss4中使用配置发送邮件
- 使用JBoss配置发送邮件
- linux配置使用外部smtp发送邮件
- 自学Zabbix3.10.2.1 linux如何配置使用sendEmail发送邮件
- 使用SQLServer2000 发送邮件详细配置过程
- Java mail使用QQ邮箱发送邮件配置方案及异常处理
- linux配置使用外部smtp发送邮件
- Django-Python Django 使用 QQ / 新浪邮箱发送邮件配置
- Linux下配置mail使用外部SMTP发送邮件
- 使用SQLServer2000 发送邮件详细配置过程
- ubuntu下使用mutt和msmtp发送邮件的简单配置
- 二代CMS旅游网站程序V1使用手册(八):邮件发送系统配置管理
- 使用SQLServer2000 发送邮件详细配置过程
- Postfix邮件服务器的原理和postfix + dovecot配置,使用Thunderbird发送邮件和SMTP认证
- 使用PHP邮件库swiftmailer发送邮件时,QQ,163邮箱的配置
- 使用.net的SmtpMail发送邮件及本机SMTP的简单配置
- dede使用phpMailer类配置微软邮箱发送邮件
- 使用SQLServer2000 发送邮件详细配置过程
- 使用SQLServer2000 发送邮件详细配置过程