Probaj ovo:
Function SndOtlkMsg(DisplayMsg As Boolean, Optional strAttachmentPath) As Boolean
'HARD CODED EXAMPLE
'To test this procedure, type the following line in the
'Debug window, and then press ENTER:
'SendOutlookMessage True, "C:\My Documents\Customers.txt"
'
'If Exchange scurity is troubling you, then:
'When warning about "Program Trying to acces Address Book" appears,
'select "Allow Access for 10 minutes (try more) and you will be OK - for 10 minutes
'Next message, "Someone trying to send the message" apparently can not
'be ignored, so press Yes when it appears
'
On Error GoTo ERROR_HANDLER:
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
SndOtlkMsg = False
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("
[email protected]")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("
[email protected]")
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("
[email protected]")
objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceNormal '= olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(strAttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(strAttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
SndOtlkMsg = True
EXIT_PROC:
On Error Resume Next
Set objOutlook = Nothing
Exit Function
ERROR_HANDLER:
Select Case Err
Case Else
SndOtlkMsg = False
MsgBox Prompt:=Err.Description, Title:="Error " & Err.Number & " in SndOtlkMsg()"
End Select
Resume EXIT_PROC:
End Function
Sve sto je hard kodirano moze da se prosledi kao funkcijski parametar (ako se prvo napise funkcija, naravno) i to je to. Ako na tvojoj mrezi deluje Exchange security patch, onda ce da te pita da lio zelis da dozvolis "tom i tom programu da aktivira Outlook", tu ti moze pomoci jedino tvoj sistem aministrator tako sto ce podesiti security settings za odredjene users, ali to je nezgodan posao i IT administratori to ne vole da rade. Sta ces, taman smo naucili kako da iz drugih aplikacija pozivamo Outlook, kad Microsoft odluci da je to opasno i na nivou Exchange servera pokvari celu stvar.
Ima i drugih resenja, sa CDO i CDONT bibliotekama, ali na kraju sve zavisi od security settings na Exchange serveru.
:-)
:-)