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
| ' This also appears as the "QuickStart" example in "Overview"
Function QuickStart()
Dim objSession As Object ' or Dim objSession As MAPI.Session
Dim objMessage As Object ' or Dim objMessage As Message
Dim objOneRecip As Object ' or Dim objOneRecip As Recipient
On Error GoTo error_olemsg
' create a session then log on, supplying username and password
Set objSession = CreateObject("MAPI.Session")
' change the parameters to valid values for your configuration
' IMPORTANT: Storing user names and passwords inside source code
' can lead to security vulnerabilities in your software. Do not
' store user names and passwords in your production code.
objSession.Logon 'profileName:="User One", _
'profilePassword:="my_pword"
' create a message and fill in its properties
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Sample Message"
objMessage.Text = "This is some sample message text."
' create the recipient
Set objOneRecip = objMessage.Recipients.Add
objOneRecip.Name = "UserOne"
objOneRecip.Type = CdoTo
objOneRecip.Resolve
' send the message and log off
objMessage.Update
objMessage.Send showDialog:=False
MsgBox "The message has been sent"
objSession.Logoff
Exit Function
error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Resume Next
End Function |
Partager