Secondary Development of WinWebMail Mail System Interface

Source: Internet
Author: User
Tags email account

WinWebMail is a lightweight email server system suitable for small and medium-sized enterprises. It has complete functions. For more information, see the official website: 3.7.6.1 Enterprise Edition, during installation, it automatically generates website file directories, all of which are ASP pages. in IIS, create a virtual directory pointing to the Web folder and Configure permissions according to some of its instructions, in this way, we can use its email service on the webpage.

Its Web Client is relatively simple, but all of its functions are available. the first time you use admin to add a domain, and then add another user, we will have the mailbox for this domain name. NOTE: If your machine does not have an independent network IP address or the domain name is not resolved to you, you can also add a domain, for example, I add a microsoft.com domain, and then add a user jonllen to it, then I log into the jonllen@microsoft.com user, I can also send out the mail with its user name, haha, but the other party should see in the spam, generally, the email server checks whether the email domain name and the source of the email are in the same place. If it is not in the same place, it deems the email as a fake spam and you cannot receive the reply from the recipient, because microsoft.com is not resolved to you, let's take a look at a WinWebMail post-login.

It is often not enough to send emails only on Web pages. for example, the system automatically sends emails and sends emails in a scheduled group. These operations cannot be manually sent to its page. Instead, you must be able to call its interface in the program to send emails, in addition, you may need to develop a set of OA recently, which requires enterprise mail. To register an account in OA, you need to open an email account and create an employee address book. The email information is internal communication, it can also be directly sent to external mailboxes. However, WinWebMail seems to provide interfaces in the form of Web page access, but open the asp page in it, we can see some such code.

Dim ei
Set ei = server. createobject ("easymail. InfoList ")
Username = Session ("wem ")
Ei. LoadMailBox username, trim (request ("mode "))
'-----------------------------------------

Anyone familiar with asp knows that it uses server. createobject is used to create an object. For example, server is used for data connection operations. createobject, while the variables in asp are weak variable types that can be used without being declared, the above Code contains server. createobject ("easymail. infoList ") What object is created? Suddenly, WinWebMail has a C/S client interface, but the operation can be seen only when it is on the server. The function is relatively simple, and users and configuration domains can be added, you can also modify some system settings, open task management, and view all processes. You can see that it is actually a program, you can also close it, but there is also a process named emsvr, it is the background service of the WebWinWeb mail system. The core is here! So how do they implement mutual calls? Careful programmers will soon think of using COM components, because COM components can conveniently call and communicate with each other through interfaces, or even add references to VS for different languages, and select COM components, there are components of WinWebMail, such.

So, the above server. createobject can be interpreted as creating the called COM component object. since the COM component interface can be called, it is easy to do. because the COM component interface can be called across any language, if it is a standard DLL component, we can also reference it using an unmanaged dynamic link library method, but it seems that you must all know some of its method names and parameters. can't I find them one by one on those asp pages? In addition, if you do not have relevant documents, you must first understand the entire page logic. Even if you have found them, it is not necessarily the method name you want. How should we change it? Didn't VS be used to reference COM above? That's right! We add the COM component of WebEasyMail to the project. VS will automatically generate an Interop. EASYMAILLib. dll file to the Bin directory, which is opened in the object browser. The interface attribute classes in the directory are listed as follows.

We need to call the COM interface, so the class we call it to generate is so simple and convenient. when writing code, we first instantiate the class in it. We can see that there are many methods and attributes in the class. at the beginning, you may not understand some of its attributes and methods. however, you can open the code on its asp page and take a look at the entire process of calling it. Maybe you have some thoughts. for general purposes, I used C # To write some common operations as the WebService method. here I post a method to return the user's Folder Information (including name, total quantity, and number of new mails.

[WebMethod (Description = "the returned mailbox contains the name, number of mails, and size")]
[System. Xml. Serialization. XmlInclude (typeof (MailBox)]
[SoapHeader ("Usheader", Direction = SoapHeaderDirection. In)]
Public MailBox [] GetMailBoxes (string username)
{

InfoListClass infos = new InfoListClass ();
If (! Username. Contains ("@"))
Username + = System. Configuration. ConfigurationManager. receivettings ["EmailPostfix"];
Infos. LoadSizeInfo (username );
System. Collections. Generic. List <MailBox> list = new System. Collections. Generic. List <MailBox> ();
List. Add (new MailBox ("inbox", "in", infos. inboxMailCount, infos. newInBoxMailCount, infos. inboxMailSize ));
List. Add (new MailBox ("draft box", "out", infos. outboxMailCount, infos. newOutBoxMailCount, infos. outboxMailSize ));
List. Add (new MailBox ("poster", "sed", infos. sendboxMailCount, infos. newSendBoxMailCount, infos. sendboxMailSize ));
List. Add (new MailBox ("bin", "del", infos. delboxMailCount, infos. newDelBoxMailCount, infos. delboxMailSize ));
For (int I = 0; I <infos. PerFolderCount; I ++)
{
MailBox box = new MailBox ();
Infos. GetPerFolderInfo (I, ref box. name, ref box. mailcount, ref box. size, ref box. newmailcount );
Box. code = box. name. ToString ();
List. Add (box );

}
List. Add (new MailBox ("Total", "all", infos. allMailCount, infos. allNewMailCount, infos. allMailSize ));
Return list. ToArray ();

}

Other domains, users, and emails can also be written by analogy. However, you may need to refer to some methods on its asp page to obtain the results only after correct calls. note: There is no entity object model in its interface, and all the results in it are assigned values using ref. Multiple results are obtained through the for loop, it seems that the asp page is also called like this. debugging is also depressing. because it is a local LAN in the company, I can't even call the methods I wrote above, and no error is reported, that is, no result is returned, but you can do anything in its asp Website! I have been depressed for a long time. later, I uploaded the code to the server and accessed it directly using WebService. that proves that the methods I wrote are correct. Is there a problem? I still don't quite understand.

However, since it can run on the server, it is OK, because the mail server will eventually be deployed on the server, in this way, we can also provide WebService methods for adding users, enterprise address book, and sending and receiving emails, if the company also has OA, ERP, human resources management systems, and so on can be easily called, and unified user management under the domain can be achieved, mail communication between enterprise users and employees. if you want to use the email system, consider using WinWebMail.

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.