Mail applications written with PB

Due to strong characteristics database cover-up, PB unknown mail function. In VB, you can easily send mail using CDO control (using Delphi NMSMTP), while the PB in the mail function is more flexible than they help.


unique technology and efficient database access, won the majority of programmers of all ages. On the surface, it seems appropriate to develop database applications and, in fact, in accordance with PB standard MAPI interface, the letter stated, developed a number of internal functions and data structures used to support e-mail, it is also a very good development tools Mail applications.

mail application to respond to basic services include: log on to the mail server to start the session, sending and receiving mail, e-mail at the end of the session. PB, all these services are launched around the object mailSession therefore programming need to define a main window type instance variables: mailSession MyMail

Then in the event Open initialization is:
MyMail = Create mailSession

1. Log on to the mail server

MyMail later after initialization, but also mailLogon order to connect to a mail server:

MyMail.mailLogon (“jq75″, “Alexander” mailNewSessionWithDownLoad)

The first two parameters are username and password, if they are ignored when executing a dialog recording appears. The last parameter that creates a new conversation e-mail, and the mail server is downloaded jq75 his inbox.

Figure 1

2. Reading mail

User information after validation of the server, a valid e-mail conversations to develop the next to do is to send and receive messages.

PB with a MailMessage object to describe a message, the object encapsulates the theme of the message, the address, the message body and attachments, and other information. Figure 1 is reading e-mail application interface, which lists all the messages in the Inbox, choose which one to read. The main window Open event code:

File …… / / connect to the mail server
MyMail.mailGetMessages ()
file / / use the e-mail box filled MyMail object
inum = UpperBound (MyMail.MessageID [ ])
file / / Returns the number of messages in the inbox
For i = 1 To inum file / / read inbox each message, and the theme has been added to the area
MyMail.mailReadMessage list (MyMail.MessageID [i], msg, mailEntireMessage!, True)
-tab-1.tabpage 1.plb-1.AddItem (msg.Subject, 1)
Next file / / MailMessage msg type instance variables
PLB-1 control selectionChanged event add the following code:
MyMail.mailReadMessage (] MyMail.MessageID [index, msg, mailEntireMessage! , True)
msg.Subject SLE-1.Text =
file / / View topic current message
sle-2.Text = msg. beneficiary. [1] Address
file / / display the address of the sender
sle-3.Text = msg.DateReceived
file / / Show pickup time
MLE-1. text = msg.NoteText
file / / display the message body of the message
iAttachmentFileNum = UpperBound (msg.AttachmentFile [])
file / / get the current number of e-mail Fixing
For i = 1 To iAttachmentFileNum
strAttFile = strAttFile msg.AttachmentFile + [i]. PathName + “~ r ~ n”
Next file / / strAttFile as instance variables of type String

“Schedule” button click event add the following code:

MessageBox (“attachment”, strAttFile) file / / view the attachment current e-mail and its location on the hard disk storage


3. Send e-mail

Figure 2 is to send an e-mail application interface, it receives the recipient’s address, subject line, message body and attachments, used to fill a MailMessage object type MSG then send. “Add Attachment” button is used to select a file on disk, click the event code:

Figure 2

DocName String, Integer named

GetFileOpenName Value = (“select attachment” DocName named, “DOC”, “All Files (*. *) *. *” )
If the value = 1 then
PLB-2.AddItem (DocName, 1)
file / / DocName must include the full path information
“Delete Attachment “button is used to delete the file has been added, click the event code:
Ind = PLB-2.SelectedIndex ()
If -1 then Ind PLB-2. DeleteItem (Ind)
“Send” event code button clicked:
sle_4.Text msg.Subject file = / subject line /
msg.NoteText 2.Text file = male / message body /
[Msg.Recipient 1]. RecipientType = mailTo!
File / / specified recipient type mailTo!
Msg.Recipient [1]. Address = ‘SMTP:’ + sle-5.Text
file / / address of the recipient must be preceded with SMTP
For i = 1 to PLB-2.TotalItems ()
file / / add the selected files in the annex
msg.AttachmentFile [i]. FileType = mailAttach! file / / specify the type of accessories i
msg.AttachmentFile [i]. PathName = 2.Text PLB-(i) the file / / the file attachment full name i

Next MyMail.mailSend (msg) / / Send an email

4. End of conversation e-mail

the “Exit” button If you click on add the following code:

MyMail.mailLogoff () file / / end of the conversation e-mail
Destroy MyMail file / / destroy the session object

Thus, a single e-mail application on the series, even if it is not sufficient and Foxmail, Outlook comparable, but even their most basic functions.

program debugging through PB6.5 example, most of the code can be used directly.

Leave a Comment