Send and receive mail in VB, VFP application

zhaozj2021-02-11  229

In VB, VFP application, sending mail e-mail is one of the most important ways of Internet / intranet online communication, making full use of E-mail's functionality to greatly improve enterprise work efficiency, mitigation of users' work burden. The Windows 95 provides an email client named Exchange, which contains functions such as inbox, outbox, transceiver message, message priority, widely supporting hypertext messages, sending and receiving faxes, and Internet mail. Work in a variety of software environments such as LAN, Microsoft Fax, remote emails, and Internet. In the application system developed by VFP, VB, combined with Exchange mail service features, you can make your application system more powerful, more complete service, more convenient. The MAPI controls of VB, VFP are described below, and these controls are used to send and receive E-mail in VB, VFP applications. I.MAPI Control Overview MAPI (Communication Application Interface) Control, MSMapi32.ocx, including two OLE controls: MapiSession control and MapiMessage (MAPI message) control. The function of the Mapisession control is responsible for establishing a session and canceling a MAPI working period of the session. The MAPIMESSAGE control provides all the functions of all emails to emails, etc. The mapisession control is used to register a new working period and logout current working period. When registering, first establish a session connection with the E-mail server with the Signon method of the mapisession control. After the Registration dialog is displayed, the sessionID property contains the handle of the just registered mapping. This handle must eventually be passed to the MapimESSAGE control, and the working period must be logged out before ending the current Mapisession work period. Then use the MAPIMESSAGE sessionID attribute to connect with a valid session, perform a series of message system functions, and implement the ability to send and receive mail. II. The main attribute of MAPI control (1) Attributes of the mapisession control: Action property: When the Mapise Control is activated, this property will determine what operations do. LogonUI attribute: This property specifies whether the registration dialog is displayed. When its value is "true", a dialog prompts a new user to enter a username and password; when its value is "false", the dialog is not displayed. SessionID Property: Returns the current message session handle. When specifying a Signon method, the value of this property can be set. This session handle is required to use the MapimAge control to process the message, and the default value is zero. Signon method: Log in to the account specified by the user and the password property and store the session handle to the properties sessionid. Signoff method: End message session, exit from the account specified by UserName and Password properties. (2) Properties of the Mapimestage control: Action property: When the MapiMessage control is activated, this property determines what action will be performed. SessionID Property: Stored a message session handle returned by the SESSIONID property of the mapisession control. FetchSorted Properties: Specify or return the sort of the message when populating messages in the message in the inbox. When its value is "true", add a message to the message collection in the order of the receiving message; when the value is "false", a message is added by the user inbox. FetchunReadonly property: Decide whether to limit the message in the message collection as unread message.

When its value is "true", only the unread message specified by the FetchMsgType property is added to the message collection; when the value is "false", the appropriate type of all messages in the inbox is added. Msgcount property: Used to return the total number of messages existing in message settings during message work. MsgIndex Property: Specifies the index number of the current index message. When the index changes, all other properties of all messages also change to reflect the characteristics of the index message. The range of index numbers is from -1 to msgcount-1. MSGORIGDISPLAYNAME Properties: Returns the name of the original sender of the current index message. MsgorigAddress properties: Returns the original sender's email address of the current index message. RecipdisPlayName, Recipaddress, Msgsubject, MsgntetExt Properties: Specify the current indexed recipient name, recipient's email address, theme, text line, constitute a complete message. Send method: Send a message. It comes with a parameter nDialog. When nDialog is "true", the operation interface of the Exchange mail system is displayed, and the user enters the message of the message, and the message is submitted to the mail server; when nDialog is "false", it is not displayed. The corresponding operation interface is submitted to the mail server. Reply method: Respond to a message. Copy the current index message to the constituent buffer and put the Re: Add the beginning of the title row, and set the msgIndex property to -1. Delete method: Delete a message, recipient, or attachment. Compose method: constitutes a message. Fetch method: Create a message collection by the message selected by the inbox. III. Application example ★ Application example 1: send and receive emails with the MAPI control of VB 5.0. 1. Method of inserting the MAPI control: Select the component (0) in the "Project" item of the VB 5.0 main menu, in the pop-up control bar, double-click the "Microsoft Mapi Control 5.0" item, and press the "OK" button to return. Then, there is the above control in the form toolbox.

2. Establish a form containing the following controls: Control Name Caption Main Factory FRMMAIL MAPI Control MAPIMAIL Control MALSESS MAPIMESSAGET MAPILMAS command button cmdnewmail Outbox Command button CMDGETMAIL Inbox Command Button Cmdexit Exit Subform FRMNewmail Outbox Label Label1 Recipient: Tag Label2 Topic: Text Box Text1 'Enter Recipient Email Address Text Box Text2' Enter Text Subject Text Box TEXT3 'Enter Text Content Command Button Mailsend Send Mail Subform FRMGETMAIL Inbox Label Label1 sender: Label Label2 Topic: Text Box Text1 'Sender Email Address Text Box Text2' Text Theme Text Box Text3 'Text Content Command Button CMDPREVIOUS Wide Command Button CMDNext Enter the program code for the main form "Outbox" button backward: private subdnewmail_click () frmnewmail.show end sub Enter the program code for the main form "Inbox" button: private subdgetmail_click () frMgetmail.show end sub Enter the program code for the main form "Exit" button: private subdexit_click () frmmail.mailss.signoff 'Disconnects End End Sub Enter the program code for the FRMNEWMail Subform "Send Mail" button: private submailsend_click () frmmail. Mailsess.signon 'Establishing connection frmmail.mailmess.SessionId = frmmail.mailsess.SessionId frmmai l.MailMess.MsgIndex = -1 frmMail.MailMess.RecipDisplayName = Text1.Text frmMail.MailMess.MsgSubject = Text2.Text frmMail.MailMess.MsgNoteText = Text3.Text frmMail.MailMess.Send (False) frmMail.MailSess.SignOff End Sub input frmGetMail subform loaded program code: Private sub Form_Load () Dim mailIndex, mailCounts As Integer frmMail.MailSess.SignOn frmMail.MailMess.SessionID = frmMail.MailSess.SessionID frmMail.MailMess.FetchSorted = True frmMail.MailMess.FetchUnreadOnly = True frmmail.mailmess.action = 1 mailcounts = frmmail.mailmess.msgcount if mailcounts = 0 TEEN TEXT3.TEXT = "There is no email in the inbox! "

frmGetMail.cmdPrevious.Enabled = False frmGetMail.cmdNext.Enabled = False Else frmGetMail.MailMess.MsgIndex = 0 frmGetMail.Text1.Text = frmMail.MailMess.MsgOrigAddress frmGetMail.Text2.Text = frmMail.MailMess.MsgSubject frmGetMail.Text3.Text = frmMail.MailMess.MsgNoteText End If End sub input frmGetMail subform "forward" button of the program code: Private sub cmdPrevious_Click () mailIndex = frmGetMail.MailMess.MsgIndex frmGetMail.MailMess.MsgIndex = mailIndex - 1 frmGetMail.Text1.Text = frmMail.MailMess.MsgOrigAddress frmGetMail.Text2.Text = frmMail.MailMess.MsgSubject frmGetMail.Text3.Text = frmMail.MailMess.MsgNoteText If mailIndex = 0 Then frmGetMail.cmdPrevious.Enabled = False End If End sub input frmGetMail subform "to after "button program code: Private Sub cmdNext_Click () mailCounts = frmGetMail.MailMess.MsgCount - 1 mailIndex = frmGetMail.MailMess.MsgIndex frmGetMail.MailMess.MsgIndex = mailIndex 1 frmGetMail.Text1.Text = frmMail.M ailMess.MsgOrigAddress frmGetMail.Text2.Text frmGetMail.Text3.Text = frmMail.MailMess.MsgNoteText If mailIndex = mailCounts Then frmGetMail.cmdNext.Enabled = False End If End Sub ★ = frmMail.MailMess.MsgSubject two application examples: with the VFP 5.0 MAPI control send and receives mail. 1. Method for plugging the MAPI control: Select "Options" in the Tools item of the VFP 5.0 main menu, in the pop-up control bar, double-click the Microsoft Mapi Control 5.0 item, then in the form toolbox The above controls.

2. Establish a form containing the following controls: Control Name Caption Forms FRMMail with VFP 5.0 MAPI Control send and receive mail mapisession control MAILSESS MAPIMESSAGE control MailMess command button Command1 Outbox Command button Command2 Inbox Command button Command3 Exit Enter "send" box "button click event program code: thisform.MailSess.SignOn thisform.MailMess.SessionID = thisform.MailSess.SessionID thisform.MailMess.MsgIndex = -1 thisform.MailMess.RecipDisplayName =" zjport@public.jsinfo.com.cn "Thisform.mailmess.msgsubject =" letter "thisform.mailmess.msgnotetext =" Please send me an email! "Thisform.mailmess.send (.f.) Thisform.mailsess.signoff Enter the Inbof button Click the event program code for:.. thisform.MailSess.SignOn thisform.MailMess.SessionID = thisform.MailSess.SessionID thisform.MailMess.FetchSorted = .T thisform.MailMess.FetchUnreadOnly = .T thisform.MailMess.Action = 1 xx = '' for mm = 0 to thisform.mailmess.msgcount-1 thisform.mailmess.msgindex = mm xx = xx thisform.mailmess.msgnotetext chr (13) chr (10) endf thisform.mailsess.signoff input "exit" The program code of the button: thisform.mailsess.signoff release thisform The above program is only given a simple case for developing the E-mail program with VB 5.0 and VFP 5.0. Users can make the above program, improve the above program, and add them. In your own application, make the application system more powerful. The above programs are running and passed in the same way in Tongchuang P / 200, Chinese Windows 95, Windows NT 4.0, Visual FoxPro 5.0, Visual Basic 5.0.