首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

james邮件服务器上的邮件发送

2012-10-10 
james邮件服务器下的邮件发送1. 环境搭建????下载JDK??? 下载james 到apache网站下载:http://apache.freel

james邮件服务器下的邮件发送

1. 环境搭建

????下载JDK

??? 下载james 到apache网站下载:http://apache.freelamp.com/james/server/apache-james-2.3.2.zip

????下载javamail相关jar包

2. 启动james

??? 进入james安装目录:C:\james-2.3.2\bin

??? 运行run.bat

??? 默认我们不更改C:\james-2.3.2\apps\james\SAR-INF 下的config.xml

??? 这样邮件服务器的域名默认为localhost

3. 建立用户

????telnet localhost 4555

??? 用roor/root登入

????执行

??? adduser VerRanLiu 123456

??? adduser dove 123456

??? 这样我们建立的两个用户邮箱地址为:VerRanLiu@locahost dove@localhost

4. 编写发送邮件客户端类

?? 让VerRanLiu 给dove 发送一封邮件

package com.spring.mail;import javax.mail.*;import java.util.*;import javax.mail.internet.*;public class MyFirstMail {protected Session mailSession;public MyFirstMail() throws Exception {init();}public static void main(String[] args) {try {new MyFirstMail().sendMail();System.out.print("邮件已发");} catch (Exception e) {e.printStackTrace();}}// 初始化服务器环境public void init() throws Exception {Properties props = new Properties();props.put("mail.transport.protocol", "smtp");props.put("mail.smtp.host", "localhost");props.put("mail.smtp.port", "25");mailSession = Session.getDefaultInstance(props, null);;}public void sendMail() throws Exception {try {Message msg = new MimeMessage(mailSession);// 从哪里发的邮件msg.setFrom(new InternetAddress("VerRanLiu@localhost"));// 发送到目标邮件// msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("wang@localhost"));// 抄送的接收者// msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse("wang@localhost"));// 暗送的接收者msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse("dove@localhost"));// 设置发送时间msg.setSentDate(new java.util.Date());// 设置邮件标题msg.setSubject("a test mail");// 设置邮件内容msg.setText("this is the email content");// 指定协议发送消息的对像Transport transport = mailSession.getTransport("smtp");// 发送消息Transport.send(msg);} catch (Exception e) {throw e;}}}

?

5. 查看发送的邮件信息

C:\james-2.3.2\apps\james\var\mail\inboxes\dove

查看 4D61696C313238303330373733313339302D31.Repository.FileStreamStore 文件

Return-Path: <VerRanLiu@localhost>Delivered-To: dove@localhostReceived: from localhost ([127.0.0.1])          by 1c6b13dd5c124b1 (JAMES SMTP Server 2.3.2) with SMTP ID 1010          for <dove@localhost>;          Wed, 28 Jul 2010 17:02:11 +0800 (CST)Date: Wed, 28 Jul 2010 17:02:10 +0800 (CST)From: VerRanLiu@localhostMessage-ID: <11850709.0.1280307730828.JavaMail.Administrator@1c6b13dd5c124b1>Subject: a test mailMIME-Version: 1.0Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitthis is the email content

?

?

1 楼 Vicent_Lee 2011-03-10   我还是不明白啊 、有没有完整的代码啊、谢谢 2 楼 VerRan 2011-03-10   上面的代码就是可以直接运行的。 3 楼 VerRan 2011-03-10   Vicent_Lee 写道我还是不明白啊 、有没有完整的代码啊、谢谢
上面的代码是可以直接运行的

热点排行