使用JSP开发WebMail系统_MySQL
WebMail
电子邮件(E-mail)是Internet上使用最广泛的服务之一,传统的Email应用模式基于C/S结构,即用户使用客户端的邮件收发工具(如Outlook、Foxmail等)与提供邮件服务的服务器(如163.net、263.net、371.net)通信,在使用客户端邮件工具之前,用户要进行一些必要的设置,如指定邮件服务器的主机地址和通信端口等,这些工作对刚开始上网的用户会有一定的困难,如果把E-mail和Web结合在一起,即通过Web编程和适当的系统设置,使用户仅仅以访问Web的方式就可以得到和使用完整的邮件服务,这样将极大地方便上网用户,这种系统称为WebMail。WebMail是目前Internet上最受欢迎的服务之一,也是很多网站必备功能之一。另外WebMail同样也适用于企业或校园网的应用。
通常在后台服务器的搭建和设置完成后实现WebMail系统,而前台的开发工作主要是开发工具与后台数据库和邮件服务器的交互问题。在Linux平台上运行的各种服务器软件稳定性和可靠性一直很好,而且选择跨平台的Java开发工具使系统更稳定,具有更高的伸缩性。
尽管JSP提供强大的功能是建立在Servlet之上,但JSP的性能和Servlet相差无几。JSP首先要编译成Servlet,这只会增加少量的代码,仅需编译一次且可以预编译,这就消除了运行时花费不必要的负担。JSP与Servlet性能上的差异仅仅表现在返回的数据是二进制的。这是因为JSP返回时用的是PrintWriter,而Servlet可以应用于速度更快的OutputStream。
JSP自定义的标签库可以封装大量的、复杂的Java操作在一个Form里面,这些预先定义好的标签可以很容易的被那些没有Java知识的人调用。因此,JSP自定义的标签库可以有效地实现Java程序员和Web设计人员工作的划分。然而,在页面上应用的每一个标签,Web容器都必须创建一个新的标签句柄对象或从标签缓冲中提取它。因此,过多的应用自定义的标签将会带来不必要的资源浪费。
BodyTags是一种特殊的定制标签,可以提取在它之间封装的内容或者替换那些内容。BodyTags之间的内容一般会备份在内存中。由于BodyTags之间能够嵌套和重复,因此,在程序中应用了多级的BodyTags会占用大量宝贵的内存和系统资源。
该系统提供了获取、阅读、书写、转发、回复、打印、删除及用户管理的功能。考虑到系统的跨平台性,采用Java及相关技术产品为开发工具,特别是采用JSP作为服务程序,这样对客户端也没有其它要求,同时系统的性能在高负荷下得到进一步提高。整个WebMail系统全部采用纯Java代码,服务器端每响应一个服务请求启动一个线程,而不像CGI那样启动一个进程。这样能够节省系统资源,提高系统性能。
获取用户输入的信息
对于用户输入内容获取功能是通过getParameter方法来实现的,对于输入的文本内容,通过如下代码就能在服务器端获取,程序代码如下:
<ccid_code>String username=request.getParameter("login");
String password=request.getParameter("password");
Session session2=Session.getInstance(System.getProperties() ,null);
Store store=session2.getStore("pop3");</ccid_code>
根据用户输入的信息来连接服务器,程序代码如下:
<ccid_code>try{
store.connect(host,username+"%nyist.net", password);
}
catch(javax.mail.AuthenticationFailedException e)
{content="用户名与密码不匹配";}</ccid_code>
接收邮件代码段
根据获取用户输入的信息来连接服务器,代码为:
<ccid_code>store.connect("nyist.net",-1,request.getParameter("username")+"%nyist.net",request
.getParameter("password"));</ccid_code>
获取服务器端的信息,代码如下:
<ccid_code>Folder folder = store.getFolder("INBOX");
Folder.open (Folder.READ_WRITE);
Message message[]=folder.getMessages();
FetchProfile fp=new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
fp.add("X-Mailer");
folder.fetch(message,fp);</ccid_code>
根据服务器上信息的不同格式,使用不同的方式来读取:
<ccid_code>String contentbody="";
Object o=message[j].getContent();</ccid_code>
若其Type为tex/plain就可直接读出,代码如下:
";
StringBuffer buf=new StringBuffer(contentbody.length()+6);
char ch=' ';
for(int p=0;p<ccid_code>if (message[j].isMimeType("text/plain"))
{
contentbody=(String)+"</ccid_code>
");
else buf.append(ch);
}
contentbody=buf.toString();
}
如果信息类型为text/html,不同的信息类型处理的方式稍有不同(如下段代码),由于篇幅有限不再一一说明。
";<ccid_code>else if (message[j].isMimeType("text/html"))
contentbody=(String)o+"</ccid_code>
发送邮件代码段
根据用户输入的内容,获取邮件头信息代码如下:
<ccid_code>String host = "nyist.net";
String from = request.getParameter("from");
String to = request.getParameter("to");
String subject = request.getParameter("subject");
String content = request.getParameter("content");
Properties props = System.getProperties();
//设置邮件服务
props.put("mail.smtp.host", host);
Session session2 =Session.getInstance(props, null);</ccid_code>
设置邮件头信息代码如下:
<ccid_code>MimeMessage message =new MimeMessage(session2);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject(subject);
message.setSentDate(new Date());
// create the message part
MimeBodyPart messageBodyPart =new MimeBodyPart();</ccid_code>
设置邮件内容,构建程序段如下:
<ccid_code>messageBodyPart.setText(content);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);</ccid_code>
用户在发送邮件时常常带有附件,就是将浏览器客户端用户本地的文件传送到POP客户端,实现代码如下:
<ccid_code>for (int i=0;i<mysmartupload.getfiles com.jspsmart.upload.file myfile="mySmartUpload.getFiles().getFile(i);" if myfile.saveas myfile.getfilename count></mysmartupload.getfiles></ccid_code>
在上传附件的同时,对上传文件的数量进行统计,并通过out.println("上传了"+count + "个文件")将其在屏幕上显示出来。
在发送的信件中如果有附件,使用如下代码进行发送:
<ccid_code>for(int i=0;request.getParameter("file"+i)!=null;i++)
{
messageBodyPart = new MimeBodyPart();
File file=new File("/home/mengyu/ROOT/upload/",request.getParameter("file"+i));
DataSource source =new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(request.getParameter("file"+i));
multipart.addBodyPart(messageBodyPart);
}
// Put parts in message
message.setContent(multipart);</ccid_code>
调用Transport的send方法,将构造好MIME Message对象发送出去,代码如下:
<ccid_code>Transport.send(message);</ccid_code>
删除电子邮件代码段
在通过Web界面使用电子邮件过程中,经常要对接收到垃圾邮件或已查看过的邮件进行删除,这也是电子邮件中必不可少的一个功能,所以我们设计了Web界面中删除电子邮件的相应功能,主要程序代码段如下:
<ccid_code>Folder folder=store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message message[]=folder.getMessages();
String msg[]=request.getParameterValues("msg");
for(int i=0,n=msg.length;i<n message folder.close></n></ccid_code>
用户管理
在使用系统运行的过程中,通过管理界面添加用户,删除不必要的用户,修改用户的密码,这是程序运行过程中必要的模块,代码如下:
<ccid_code>//添加用户
Runtime.getRuntime().exec("/home/vpopmail/bin/vadduser"+request.getParameter("user
name")+"@nyist.net "+request.getParameter("passwd"));
//删除用户
Runtime.getRuntime().exec("/home/vpopmail/bin/vdeluser"+request.getParameter("user
name")+"@nyist.net");
//修改用户密码
Runtime.getRuntime().exec("/home/vpopmail/bin/vpasswd"+request.getParameter("usern
ame")+"@nyist.net "+request.getParameter("passwd"));</ccid_code>
Java简化了企业解决方案的开发、部署和管理等相关的复杂问题,它是面向对象的编程语言,同时也是具有平台独立性、高性能的服务器端编程语言。它提供的标准系统框架和服务适合团体开发,可控制性好,与其它资源的集成性好。采用Java为编程工具开发高性能、高可用性的WebMail服务器具有非常重要的意义。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension
