Write an email application with PB

zhaozj2021-02-17  48

Due to the masking of powerful database functions, the email function of PB is very knowledgeable. The CDO control can be easily used in VB (using NMSMTP in Delphi), and the mail function in the PB is more flexible and convenient than they. PB has won the favor of the majority of programmers with its unique and efficient database access technology. From the surface, it seems to be only suitable for developing database applications, in fact, PB has developed many internal functions and data structures, which has developed many internal functions and data structures for support for email, so it is also a quite good Mail application development tool. The basic transaction to be processed by an email application mainly includes: logging in to the mail server to start the session, sending a message, and ending the mail session. In PB, all of these transactions are expanded around the Mailsession object. Therefore, when programming, you need to define an instance variable of this type in the main window: mailsession mymail then initialize it in the OPEN event: MyMail = Create MailSession 1. After the mail server Mymail is initialized, use the Maillogon command to connect it to a mail server: MyMail.maillogon ('JQ75', 'Alexander', MailneWSessionWithDownload!) The two parameters are user names and passwords, if they are ignored A registration dialog appears when running. The last parameter represents a new message session and downloads the server on the server to his inbox. Figure 1 2. After reading the mail user information After verifying on the server, a valid mail session is established, and the work to do is to receive the message. PB describes an email with a MailMessage object, which encapsulates information such as the subject, address, message body, and attachment. Figure 1 is a reading interface of the mail application, which lists all messages in the inbox, you can choose one of them.

The code for the main window Open event is: ... // Connect to the mail server mymail.mailgetMail object () // fill the MYMAIL object inum = Upperbound (mymail.MessageID [] // in the inbox Mail number for i = 1 to inum // Read each email in the inbox and add its topic to the list box MyMail.mailReadMessage (MyMail.MAssageId [i], msg, mailentireMessage!, True) Tab-1.Tabpage-1.PLB-1.Additem (msg.subject, 1) Next // MSG Add the following code to the instance variable for the MailMessage type: MyMail.MailReadMessage (MyMail.MailReadMessage) [Index], MSG, MailentireMessage!, true) SLET = msg.subject // Displays the topic of the current message SLE-2.Text = msg. Recipient [1] .address // Show sender address SLE- 3.Text = msg.dateReceiveD // Display Recycling Time mLE-1.Text = Msg.NoteText // Display Message IattachmentFileNum = UpperBound (msg.attachmentfile []) // Gets the number of attachments for the current message for i = 1 to attachmentfilenum strattfile = strattfile msg.attachmentfile [i] .pathname "~ r ~ n" Next // strattfile Add the following of the following example of the "Attachment" button in the "Attachment" button: MessageBox ("Mail Accessories", Strattfile) / / Displays the attachment of the current message and its position 3 stored on the hard disk. Sending Mail Figure 2 is the send interface of the Mail application, which receives the recipient address, mail topic, message body, and attachments, which are used to populate a MailMessage type object MSG, and then send it.

转载请注明原文地址:https://www.9cbs.com/read-31071.html

New Post(0)