Webmail implementation based on Linux

Source: Internet
Author: User
Tags imap mx record web database webmail server
Article title: Linux-based Webmail implementation. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Abstract: The purpose of this article is to quickly implement a Web-based email system through the application of network services and application software integrated in Linux. The author is just a fan of ordinary Linux, and tries to apply some of the learned Linux knowledge comprehensively, hoping to inspire everyone.
  
Free Webmail is a common service provided by ISPs. its biggest advantage is its convenience. you only need to use a browser to complete mailbox application, email sending, and email receiving functions. Similarly, due to the emergence of Webmail, it has greatly increased the number of ISP site visits and the site's popularity. Therefore, it is a perfect combination of the two. However, large-capacity Webmail servers are expensive due to the complexity and reliability requirements of their systems and are not suitable for the needs of the Intranet environment.
Linux, as an excellent network operating system, integrates a large number of network application software in its release versions, such as Web server (apache) and Ftp server (wu-ftp), the mail server (sendmail + imap4), the SQL database (postgresql), and so on, can quickly build an Intranet environment, and there are also exquisite mail sending and receiving programs (metamail) and powerful Web server development tool (PHP3 ). After sendmail is configured and imapd is activated, all Linux users can use client software such as Outlook to send and receive emails. Therefore, they can be applied in the set, you can implement a simple Webmail server function.
  
I. main functions and methods of Webmail are as follows:
1. Mailbox application: use exec in PHP3 to execute the useradd and edquota commands as root to create a system user, set the user's disk quota, and save the user to the postgresql User table, the requested email address will be in the form of username @ domain. If you only want to provide the Web application Mailbox function for users to use mail client programs such as Outlook for mail processing, the goal has been achieved.
2. edit Email: use the HTML form to construct the editing domain, and use the "file" type supported by IE4 and Netscape 3 to upload email attachments.
3. send mail: use exec in PHP3 to execute the sending function provided by metasend to encode and send the mail.
4. receive emails: use the powerful imap function set provided in PHP3 to receive and decode mail data and manage the inbox, split the attachment of the email into a temporary file and put it into the ftpd anonymous access directory. then, the attachment description is used to generate a hyperlink, facilitating client download.
5. account management: use exec in PHP3 to execute passwd and deluser commands to implement password change and email deletion.
  
II. The following describes the specific methods and precautions for implementing the above functions.
1. support for imap and postgresql PHP3 module compilation The RedHat 5.1 we use does not include PHP3 support, and general PHP3 execution packages do not support precompiled imap, to make full use of this excellent Web server development tool, it is best to download the source program on wwwphp.net. In fact, it is very delicate and less than 2 MB in total, as an award-winning software with 150,000 website users (Statistics in the PHP3 help document) and in the Linux world, its source code should be selected by all publishers. Because the imap support of PHP3 requires the c-client library and related header files, you should first unpack the imap4 source program package for compilation. Note that crypt can be found in the Makefile generated by make lnx during the compilation of imap4. you only need to add lcrypt to the options of the connection Library. Generally, an error occurs during compilation according to the description file of the source program, mostly because the include Or lib Directory of the Makefile file does not match the local directory.
2. upload supports attachment (attachment), which is an important part of emails. to upload client files to the server for processing, both the browser and server of the client must support it. The instructions and examples of upload processing are provided in the PHP3 help document, and IE4 and Netscape both support this function well, unfortunately, we didn't see a similar introduction in any books on HTML.
3. Introduction to metasend in Linux, generally, the mail sending and receiving program is mail, but it does not support MIME encoding and cannot set the sending address, which is not suitable for Webmail. Metasend is a mail sending program that supports the MIME standard and can set the user address and encoding method of the sending end. it is very suitable for shell commands. it is contained in the metamail package and has only 15 kb. Using it directly as the backend mail sending program, MIME encoding can effectively reduce the complexity of the program. Because PHP3 can quickly process form data and use exec to call external programs of the system, it effectively uses a large number of application software provided by Linux with flexible input/output redirection as CGI programs, it is a simple method, and it is also the strength of a Linux system for handling a large number of character interfaces or command lines.
4. because the browser restricts the write function to the local file system, the most natural way to download files is to directly use FTP for anonymous access through the browser. Since the Linux system integrates wu-ftpd, the attachments of emails are put into the subdirectories of the ftpd anonymous access in the form of temporary files, and only the nobody can be written, when the server displays the Mail information, it uses the attachment description in the mail header to generate a hyperlink, which can solve this problem simply and naturally.
5. Introduction to imap and postgresql support in PHP3 PHP3 is actually an intermediary layer for Web servers and a large number of C-database functions. It also expands the data capability for processing form submissions. In addition, it also has a style similar to C, so it can implement a variety of complex functions in a simple and efficient manner. PHP3 contains 38 functions that support imap. these functions are built on the support of standard client development libraries for the imap4 protocol, its functions and efficiency are completely reliable and guaranteed. these functions can be used to quickly connect to imapd, verify the address, receive emails, split emails, decode emails, and manage mailboxes.
The postgresql database is mainly used to verify the user and trace the temporary files generated by the user. the function is relatively simple, but the SQL-based database does not have to worry about conflicts in processing concurrent access. PHP3 supports many database systems. of course, they must have their Linux-based C development library and header files, postgresql is an object-oriented SQL database integrated into the release package, and its psql client programs are very friendly and naturally become the first choice. PHP3 provides 32 postgresql-supported functions and provides a wide range of documents and examples. it is not difficult to implement a Web database. it is important to authorize nobody in each table. PHP3 uses almost no ODBC for database access, but directly uses the development libraries provided by various databases. However, it uses similar function call formats, which is also convenient. In the PHP3 document, the type of returned values is incorrect in some cases. you can avoid this problem by testing the following before use.
6. sendmail is a widely used mail transmission system. it has a long history and powerful functions, but the configuration is complicated. However, you can use linuxconf to start its basic functions. Note: In the case of multiple email servers, the dns mx record plays a critical role. Note that you must specify a clear MX record for each domain in your DNS. When you use linuxconf to configure sendmail, you can choose not to send the mail immediately or a short queue processing time to reduce the waiting time for the client due to incorrect email address input. In addition, directly edit/etc/rc. d/init. setting a short time-out period for d/sendmail helps improve the efficiency in the Intranet environment. In fact, a deep understanding of the functions provided by sendmail is a good way to build a powerful mail system.
7. security considerations
Because our Webmail system users are Linux users, to ensure security, you cannot grant them the permission to log on directly, that is, to specify a shell that does not exist. Because the root account is used when creating a user, changing the password, or deleting the account, the password file must be hidden. it is best to cancel the telnet service or set the range of trusted hosts. The original account of the system can not be used as a webmail user account, avoiding the loss of key information due to Webmail errors.
Because the mail system is intended for multiple users, you must provide disk quota control and shorten the time limit. when uploading files, pay attention to setting the maximum file transfer length. In addition, to prevent users from exiting midway while not deleting the generated temporary files, you can set the cron task for root to process expired temporary files.
Disable nobody and ftp accounts (default)
8. Performance Optimization
If you find that your Webmail is overloaded, you can separate the integrated database service (postgresql), domain name server (named), and Web server, which can be accessed over the network.
Similarly, you can distribute users to multiple email servers to meet users' needs. after all, Linux is a low-requirement and very cheap system.
In addition, you can open the metasend source program. For more information, see directly use PHP3 to directly send emails. avoid calling the SHELL program and improve the performance. Similarly, you can use Mysql to replace postgresql.
  
The above briefly introduces our Webmail implementation methods and precautions. this is just a simple solution that we have a very superficial understanding of the Linux system, we have not carefully considered the system performance. it does not represent the true strength of Linux as an excellent network system. we just think about it in terms of simplicity and convenience, because we feel that quick implementation of its basic functions will help us better learn and use Linux. However, we are deeply aware of the charm and strength of the Linux system and a large number of software integrated with it, as well as the changes it brings to us when thinking about and solving problems, it gives us more choices. Indeed, it has given us far more than we expected.
  
  
  
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.