Design your own E-mail system with VB

zhaozj2021-02-16  48

Visual Basic 6.0 is loved by its powerful functions, with the rapid development of the Internet, and the development of VB6 applications is more and more. This article describes how to design airs in VB to design your own E-mail system.

Check if connecting Internet

When designing your own E-mail system, we need to detect if the system connects the Internet, which determines if the Internet is connected by writing a function isconnected.

Add the following code in the main program:

Private sub form_load () if isconnected = true kilbox ("You have connected Internet!") End ifif isconnected = false kilbox ("You haven't connected Internet!") End IFEND SUB

Place the following code as a module in the program:

Option Explicit /  API declarations and definitions related to registration in order to use  / Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias ​​"RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As LongPublic Declare Function RasGetConnectStatus Lib "RasApi32 .dll "Alias" RasGetConnectStatusA "(ByVal hRasCon As Long, lpStatus As Any) As Long / ON ON setting of constants and variables / Public Const RAS95_MaxEntryName = 256Public Const RAS95_MaxDeviceType = 16Public Const RAS95_MaxDeviceName = 32Public Type RASCONN95dwSize As LonghRasCon As LongszEntryName (RAS95_MaxEntryName ) as ByteszDeviceType (RAS95_MaxDeviceType) as ByteszDeviceName (RAS95_MaxDeviceName) as ByteEnd TypePublic Type RASCONNSTATUS95dwSize as LongRasConnState as LongdwError as LongszDeviceType (RAS95_MaxDeviceType) as ByteszDeviceName (RAS95_MaxDeviceName) as ByteEnd Type /  function IsConnected return status is communicated, if True then indicates communication  / public function isconnected () AS Booleandim Trascon (255) AS Rasconn95dim LG AS Longdim LPCON AS LONGDIM RETVAL AS LONGDIM TSTATUS As RasconnStatus95trascon (0) .dwsi ze = 412lg = 256  TRasCon (0) .dwSizeRetVal = RasEnumConnections (TRasCon (0), lg, lpcon) If RetVal <> 0 ThenMsgBox "Error" Exit FunctionEnd IfTstatus.dwSize = 160RetVal = RasGetConnectStatus (TRasCon (0) .hRasCon, TSTATUS) if tstatus.rasconNState = && H2000 Tenisconnected = Trueelseisconnected = false iFend Function By using the above code, we can easily understand if the current Internet is in a state. Design receiving mail

On the VB6 menu, click "Wire" dialog box, select the Microsoft Mapi Controls 6.0 control in the Control Card of the dialog box, click the "OK" button to add two icons to the Toolbox to add two icons.

Add a mapimsSage control on the Form, named mapimeAasge1; join a mapisession control, name mapisession1; add three TextBox controls, named Subject, Content, and IndexNo, change their CAPTION to the mail title, respectively. Email content and mail index marks; and join a Label control before TextBox, change the CAPTION to title, content, and index. Set the properties of MapIMessage1 as follows:

Downloadmail = true logonui = trueWession = falseuserName = "Receive E-mail" Add a button (getmail) on the Form, change its CAPTION attribute to receive mail.

Add the following program code in getMail_click (), the functionality of the program is to allow us to receive E-mail:

MAPIMessage1.FetchForm1.Caption = MAPIMessage1.MsgCountMAPIMessage1.MsgIndex = CINT (Indexno.text) Subjec.Text = MAPIMessage1.MsgNoteTextContent.Text = MAPIMessage1.MsgSubject wherein, the Fetch command mail is caught inbuffer system memory, we will After the letter caught back, you can know the number of letters by the msgcount property, then you can use the MsgIndex to set the content, title of the letter to see.

Design and send mail

When designing the mail part, we need to complete two steps:

1. EXCHANGE settings

Enter the Exchange system, select the new setup file; the required information service is displayed, select Internet Mail.

The name of the file is set to Test. The screen will display two options, you can choose to connect in a modem method or in a NetWork mode, and the author uses the Modem mode, so select Modem.

After selecting MODEM, Exchange requires us to enter Mail Server's IP Address. Enter your IP address here. Then the TRANSFORM Message mode is set to Automatic, so when we connect to the Mail server, the new information will be downloaded to the Local. Next, set the E-mail address, full name, password, and download path you use, so that the settings of the Exchange parameters are completed.

2. programming

On the VB6 menu, click "Projects → Components", pop up the Parts dialog, select the Microsoft Mapi Controls 6.0 control in the control card of the dialog, and click the "OK" button.

Add a mapimsSAGE control on the Form, name to mapimessage1, join a mapisession control, name to mapisession1, then join three TextBox controls, named Subject, Content, and Addr, add a label before three TextBox, Finally, CAPTION is changed to title, content, and address, respectively.

Set the properties of MapIMessage1 as follows:

Downloadmail = True Logonui = trueWession = falseusername = "Send E-Mail"

Here, Downloadmail is set to True, and the new MAIL is downloaded to the Local when the program and the MAIL server is first connected. Set the LogonUI to True, when the Logon name is entered in the program, the system will display a message box to allow you to enter the correct name. Since this program uses only a session, set the newsession to false. If there are many sessions to be built, set it to true. UserName is filled in our new setting file name in Exchange. If you don't fill in content, the system will display some Message Box to let you enter the file. Add three buttons logon, logoff, and send on the Form, and change their CAPTION to log in, away from the network, and send it.

Add the following program code in Logon_Click (), the functionality of the program is to log in to the Mail server:

MAPISession1.SignOnMAPIMessage1.SessionID = MAPISession1.SessionIDMsgBox "Your Id is" Str (MAPISession1.SessionID) where do is login MAPISession1.SignOn action, when you log in, as it has been the property of the MAPIMessage1 DownLoadMail control is TRUE, it can be See Message Box on the screen, the display system is downloading Mail. After the login is successful, the system will pass back a sessionID, fill the ID in the sessionID of MAPIMESSAGE1, so you can use this session to transfer E-Mail. Add the following program code in logoff_click (), the functionality of the program is to let us leave the Mail server:

Mapis1.signoff

Add the following program code in Send_Click (), the functionality of the program is to send us E-mail:

MAPIMessage1.ComposeMAPIMessage1.RecipDisplayName = Addr.textMAPIMessage1.AddressResolveUI = TrueMAPIMessage1.MsgSubject = Subject.text MAPIMessage1.MsgNoteText = Content.textMAPIMessage1.SendMsgBox "You sent successfully it!" The purpose of which is to make the Compose command RecipDisplayName you can change the content of the The E-mail address, the subject, and article content you want are filled in RecipDisplayName, MsgSubject, and Msgntetext, and then send it with the send command.

3. Test with IE 5.0 MAIL program

Perform the SEND program designed above, fill in "Sending Test" in the Title Text box, fill in the recipient's E-mail address in the address text box, enter the content you want to transfer in the Content Text box, so letters send out.

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

New Post(0)