Webmail Implementation Based on Linux

Source: Internet
Author: User
Tags mx record web database webmail server
Linux-based Webmail implementation-Linux Enterprise Application-Linux server application information. The following is a detailed description. 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), 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 centrally applied, you can implement a simple Webmail Server function.

I. Main functions and methods of Webmail

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 mail: 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 User Password Change and email deletion.

II. Specific methods and precautions for implementing the above functions

1. Support for compiling the imap and postgresql PHP3 modules

The RedHat 5.1 We use does not contain PHP3 support, and general PHP3 execution packages do not have pre-compiled imap support. We must make full use of this excellent Web server development tool, it is best to download the source program on www.php.net. In fact, it is very delicate, less than 2 MB in total, as a 150,000 Website user recognized (Statistics in the PHP3 help document) the source code of the award-winning software in the Linux world 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 support

Attachments are an important part of emails. to upload files from the client to the server for processing, you must support both the browser and server. The help documentation for PHP3 contains instructions and examples for upload processing, 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

Generally, in Linux, 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 many character interfaces or command line handlers in Linux.

4. download email attachments

Because the browser restricts the writing function to the local file system, the most natural way to download files is to directly use FTP 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. It also has a style similar to C, therefore, 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 configuration

Sendmail is a widely used mail Transmission System with a long history and powerful functions, but its 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 the users of our Webmail system are Linux users, to ensure security, we 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 your Webmail is overloaded, you can separate the Integrated Database Service (postgresql), Domain Name Server (named), and Web server, they are all accessible through 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.

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.