Link to home
Start Free TrialLog in
Avatar of ifenton
ifenton

asked on

How do I use MAPI to send an email alert

I want to send alerts automatically from windows. For example in Performance Logs and Alerts, when the processer hits 90% the alert will trigger and sends an email to a user. I know that using MAPI should be the way to do this but I don't know a thing about MAPI. Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of ampcats
ampcats

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TommyTupa
TommyTupa

I've use wmi with vbscript to do what you seek.  Here's an example of a sendmail function using MAPI with vbscript.  Please note, in Outlook 2002 this isn't going to work for you because you need tell Outlook to allow access to the application and the permissions can only be set for a certain period of time.  

Let me know if you need full examples of the performance monitoring and the MAPI stuff and I can provide them.



Function SendEmail(xAddress, xSubject, xText, ByVal xAttachments)
 ' "xAttachments" - tablou unidimensional:
 '                  lista fisierelor atasate.
 Dim objSession As Object, objMessage As Object
 Dim objOneRecip As Object
 Dim i As Integer

 On Error GoTo error_sendMsg

 Set objSession = CreateObject("MSMAPI.MAPISession")
 objSession.SignOn
 Set objMessage = CreateObject("MSMAPI.MAPIMessages")
 objMessage.SessionID = objSession.SessionID
 objMessage.Compose
 objMessage.MsgIndex = -1
 objMessage.RecipAddress = xAddress
 objMessage.AddressResolveUI = False
 objMessage.MsgSubject = xSubject
 objMessage.MsgNoteText = xText
   
 If IsArray(xAttachments) Then
  For i = 0 To UBound(xAttachments)
    objMessage.AttachmentIndex =objMessage.AttachmentCount
    objMessage.AttachmentPathName = xAttachments(i)
  Next
 End If
   
 objMessage.Send False
 objSession.SignOff
   
 On Error GoTo 0
 SendEmail = True
 Exit Function
   
 error_sendMsg:
 On Error GoTo 0
 SendEmail = False
   
End Function