1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Const olByValue = 1
Const olMailItem = 0
Const olFolderSentMail =5
Const olFolderOutbox=4


Sub Main
	' This SaxBasic script sends a document as an attachment to an email
	' Raynald Levesque 2003/01/10 rlevesque@videotron.ca
	' SPSS web site http://pages.infinit.net/rlevesqu/index.htm

	Dim appOutlook As Object	'The Outlook 2000 Application
	Dim mynamespace As Object
	Dim myfolder As Object
	Dim Newmail As Object		'The new email
	Dim strFileName As String	'The name and path of the file to send
	Dim strTo As String			'The email address of the recipient
	Dim myitem As Long 		'Contains the number of emails in the SentFolder

	' These infomation  could be passed to the script by the syntax
	strFileName = "c:\\temp\\data with labels2.txt"
	strTo = "rlevesque@videotron.ca"
	strBody ="The file is attached."
	strSubject = "Email sent by SaxBasic"

	Set appOutlook=CreateObject("Outlook.Application")
	Set mynamespace=appOutlook.GetNamespace("MAPI")
	'Set myfolder = mynamespace.PickFolder
	'myfolder.Display

	Set Newmail = appOutlook.CreateItem(olMailItem)
    Newmail.Display
	Newmail.attachments.Add strFileName, olByValue , 1
	Newmail.Body = strBody
	Newmail.To = strTo
    Newmail.Subject = strSubject
    Newmail.Send

	Set myfolder = mynamespace.GetDefaultFolder(olFolderOutbox)
  	myitem = myfolder.Items.Count
	While myitem <> 0 'Message still being sent
		Wait 1
		myitem = myfolder.Items.Count
		Debug.Print "wait...Still " & myitem & "messages in Outbox"
	Wend

	'Close Outlook
	mynamespace.application.Quit
	Debug.Print strFileName & " has been sent..."
End Sub