723 727




Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Listing 21.3 email.frm version 1


VERSION 6.00
Object = "{20C62CAE-15DA-101B-B9A8-444553540000}#1.1#0"; "MSMAPI32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3405
ClientLeft = 60
ClientTop = 345
ClientWidth = 5970
LinkTopic = "Form1"
ScaleHeight = 3405
ScaleWidth = 5970
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 2175
Left = 240
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 2
Top = 120
Width = 5415
End
Begin VB.CommandButton Command2
Caption = "Read email"
Height = 495
Left = 360
TabIndex = 1
Top = 2520
Width = 1215
End
Begin MSMAPI.MAPISession MAPISession1
Left = 1440
Top = 1920
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DownloadMail = -1 'True
LogonUI = -1 'True
NewSession = 0 'False
End
Begin MSMAPI.MAPIMessages MAPIMessages1
Left = 2640
Top = 1920
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
AddressEditFieldCount= 1
AddressModifiable= 0 'False
AddressResolveUI= 0 'False
FetchSorted = 0 'False
FetchUnreadOnly = 0 'False
End
Begin VB.CommandButton Command1
Caption = "Send email"
Height = 495
Left = 4320
TabIndex = 0
Top = 2520
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()

MAPISession1.DownLoadMail = False
MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.MsgIndex = -1
MAPIMessages1.Compose
MAPIMessages1.Send True

MAPISession1.SignOff
End Sub
Private Sub Command2_Click()
MAPISession1.DownLoadMail = True
MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch

MAPIMessages1.MsgIndex = 0
Text1.Text = MAPIMessages1.MsgNoteText

MAPISession1.SignOff

End Sub


Reading Email In Visual Basic
Now that we’ve seen how to send email (see the previous topic), how do you read email? You set the MAPISession control’s DownLoadMail property to True.
Let’s see an example. In this case, we’ll download any waiting email into the user’s Inbox and then display the first message in a text box. We’ll use the program we started in the previous topic and add the code we need to the Read Email button’s event handler. First, we set the MAPISession control’s DownLoadMail property to True, then we use that control’s SignOn method to start the MAPI session and download any waiting email into the Inbox:


Private Sub Command2_Click()
MAPISession1.DownLoadMail = True
MAPISession1.SignOn
...


Now that the email is in the Inbox, how do we reach it? We use the MAPIMessages control’s Fetch method to create a message set (you can find out how many messages are in the set with the MsgCount property). To do that, we first set the MAPIMessages control’s SessionID property to the MAPISession control’s SessionID property and then use Fetch:


Private Sub Command2_Click()
MAPISession1.DownLoadMail = True
MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch
...


Next, we display the text of the first email message now in the Inbox by setting the MAPIMessages control’s MsgIndex to 0 and using the MsgNoteText property. (Note that in a real email program, you should check to make sure there really are messages waiting here, but in this case we assume there are because we just sent one using the Send Email button—note that if your system takes significant time to deliver email messages, you might have to alter this code.) Finally we sign off the MAPI session:


Private Sub Command2_Click()
MAPISession1.DownLoadMail = True
MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch

MAPIMessages1.MsgIndex = 0
Text1.Text = MAPIMessages1.MsgNoteText

MAPISession1.SignOff

End Sub


And that’s it—we can now receive email, as you see in Figure 21.13. Now we’re sending and receiving email with Visual Basic.


Figure 21.13  Receiving email.
The code for this example is located in the email folder on this book’s accompanying CD-ROM.




Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
719 723
727 (2)
demo cgi 727
create integration workspace tm?723B43
723 (2)
727 731
mbdch20 723
723,21,artykul
ReadMe (727)
723 ROL
723,1262

więcej podobnych podstron