Send and receive emails in VB and VFP Application Systems

Source: Internet
Author: User
Send and receive emails in VB and VFP Application Systems
E-mail is one of the most important ways for Internet/Intranet Communication. The full use of E-mail can greatly improve the efficiency of enterprises and reduce the workload of users. Windows 95 provides an email client program named exchange, which includes functions such as Inbox, sending and receiving, sending and receiving, and message priority, supports hypertext messaging, sending and receiving faxes, Internet mail, and other content. It can work in a variety of software environments, such as lan, Microsoft fax, remote mail, and Internet. In the application system developed by VFP and VB, combined with the mail service functions of exchange, you can make your application system more powerful, more complete services, and more convenient to use. The following describes the mapi controls of VB and VFP, and how to use these controls to send and receive e-mail in VB and VFP Application Systems.

1. mapi control Overview

Mapi (communication application interface) control, that is, msmapi32.ocx, includes two Ole controls: mapisession (mapi work period) Control and mapimessage (mapi message) control. The mapisession control is used to establish a session and cancel an mapi operation period. The mapimessage control provides all functions for sending and receiving emails.

The mapisession control is used to register a new work period and cancel the current work period. First

Use the signon method of the mapisession control to establish a session connection with the E-mail server. After the registration dialog box is displayed, the sessionid attribute contains the newly registered mapisession handle. This handle must be passed to the mapimessage control. You must cancel the current mapisession before it ends. Then, use the sessionid attribute of the mapimessage control to associate with a valid session and execute a series of message system functions to send and receive emails.

Ii. main attributes of the mapi Control

(1) attributes of the mapisession control:

Action property: When the mapisession control is activated, this property determines what operations to perform.

Logonui attribute: This attribute specifies whether to display the registration dialog box. When the value is true

A dialog box prompts the new user to enter the user name and password. When the value is "false", the dialog box is not displayed.

Sessionid property: returns the current message session handle. When the signon method is specified, you can set the value of this attribute. This session handle is required when you use the mapimessage control to process messages. The default value is 0.

Signon method: log on to the account specified by the username and password attributes, and store the session handle in the sessionid attribute.

Signoff method: ends a message session, from the account specified by the username and password attributes.

Exit.

(2) attributes of the mapimessage control:

Action property: When the mapimessage control is activated, this property determines what operations will be performed.

Sessionid attribute: stores the message session handle returned by the sessionid attribute of the mapisession control.

Fetchsorted attribute: specify or return the sort of messages when filling the message set with messages in the inbox. When the value is "true", messages are added to the message set in the order of receiving messages. When the value is "false", messages are added by sorting in the user inbox.

Fetchunreadonly attribute: determines whether to limit messages in the message set to unread messages. When the value is true, only the unread messages specified by the fetchmsgtype attribute are added to the message set. When the value is false, all messages of the appropriate type in the inbox are added.

Msgcount attribute: This attribute is used to return the total number of messages that exist in the message settings during message operation.

Msgindex attribute: Specify the index number of the current index message. When the index changes, other attributes of all messages are also changed to reflect the characteristics of the indexed messages. The index number ranges from-1 to MsgCount-1.

Msgorigdisplayname attribute: returns the name of the original sender of the current index message.

Msgorigaddress attribute: return the email address of the original sender of the current index message.

Recipdisplayname, recipaddress, msgsubject, and msgnotetext attributes: Specify the Recipient Name, recipient's email address, subject, and text line of the current index to form a complete message.

Send method: send a message. It has a parameter ndialog. When ndialog is "true", the operation interface of the exchange mail system is displayed. The user enters all parts of the message and submits the message to the mail server for transmission; when ndialog is "false", the corresponding operation interface is not displayed, and the message is submitted to the mail server.

Reply method: responds to a message. Copy the message of the current index to the buffer, add re: to the beginning of the header row, and set the msgindex attribute to-1.

Delete: delete a message, recipient, or attachment.

Compose method: a message.

Fetch method: Creates a set of messages from the selected messages in the inbox.

  

3. Application Instances

★Application Example 1: Use the mapi control of VB 5.0 to send and receive emails.

1. How to insert the mapi control:

In the "project" item of the main menu of VB 5.0, select "component (0)". In the displayed control bar, double-click "Microsoft mapi control 5.0, press OK. The preceding controls are available in the form toolbox.

2. Create a form containing the following controls:

Control name Caption

Use the mapi control of VB 5.0 to send and receive emails in the main form frmmail.

Mapisession control mailsess

Mapimessage control mailmess

The command button is "Publish newmail"

Command button: inbox getmail inbox

Command button cmdexit exit

Subform frmnewmail sender

Label label1 recipient:

Label label2 topic:

Text Box text1' enter the recipient's email address

Text Box text2 'subject of the input text

Text Box text3 'input text content

Command button mailsend send mail

Sub-form frmgetmail inbox

Label label1 Sender:

Label label2 topic:

Text Box text1 'sender's email address

Text topic sent from text box text2

Text Content sent from the text box text3'

Command button forward

Command button backward

  

Enter the program code of the "publish" button in the main form:

Private sub partition newmail_click ()

Frmnewmail. Show

End sub

  

Enter the program code for the "inbox" button of the main form:

Private sub register getmail_click ()

Frmgetmail. Show

End sub

  

Enter the program code for the "exit" button of the main form:

Private sub cmdexit_click ()

Frmmail. mailsess. signoff is disconnected.

End

End sub

  

Enter the program code of the "send mail" button in the frmnewmail subform:

Private sub mailsend_click ()

Frmmail. mailsess. signon' establishes a connection.

Frmmail. mailmess. sessionid = frmmail. mailsess. sessionid

Frmmail. 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

  

Enter the program code to load the frmgetmail subform:

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 then

Text3.text = "No email in the Inbox! "

Frmgetmail. Repeated previous. Enabled = false

Frmgetmail. Specify next. 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

  

Enter the code of the "Forward" button in the frmgetmail subform:

Private sub initialize previous_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. Repeated previous. Enabled = false

End if

End sub

  

Enter the code for the "back" button of the frmgetmail subform:

Private sub branch next_click ()

Mailcounts = frmgetmail. mailmess. msgcount-1

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 = mailcounts then

Frmgetmail. Specify next. Enabled = false

End if

End sub

  

★Application Example 2: Use the mapi control of VFP 5.0 to send and receive emails.

1. How to insert the mapi control:

In the "Tools" option of the VFP 5.0 main menu, select "options". In the displayed control bar, double-click "Microsoft mapi control 5.0, the preceding controls are available in the form toolbox.

2. Create a form containing the following controls:

Control name Caption

Form frmmail use the mapi control of VFP 5.0 to send and receive emails

Mapisession control mailsess

Mapimessage control mailmess

Command button command1

Command button command2 inbox

Command button command3 exit

  

Enter the "publish" button and click the program code of the event:

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 "inbox" button and click the program code of the event:

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

  

Enter the program code for the exit button:

Thisform. mailsess. signoff

Release thisform

The above program is just a simple case of using VB 5.0 and VFP 5.0 to develop the e-mail program. After you modify and complete the above program based on your actual situation, add it to your application system to make the application system more powerful.

The above programs run and pass in the same P/200, Windows 95, Windows NT 4.0, Visual FoxPro 5.0, Visual Basic 5.0 software and hardware environment.

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.