Results 1 to 2 of 2
  1. #1
    wag
    Guest

    Emailing New Database Records

    I am developing a Web based Incident Log application using an Access database and need to be able to send a notification email to our help desk staff when a new record hits the database. Is this possible?

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Emailing New Database Records

    Yes, it is possible.
    I developed a class module that'll do the job.
    It uses de default mail client to send the mail.
    Sorry, comments are dutch but the code is pretty self explaining.


    Option Compare Database
    Option Explicit
    '************************************************* ******
    'Class clsMAPI
    '************************************************* ******
    'Algemene declaraties voor een email object.
    '************************************************* ******
    Dim objMySes As Object 'Session object voor de MAPI sessie


    Public Function SendMail(txtMailTo As String, Optional txtText As String, Optional txtSubject As String) As String
    '************************************************* ******
    'Functie voor het versturen van een mailtje.
    'De returnwaarde is een string.
    'Als de string leeg is is de toevoeging succesvol geweest.
    'Als de string niet leeg is, dan bevat de string een
    'foutboodschap.
    '
    'LAATSTE WIJZIGING:
    ' Versie 1.0 augustus 2000 B. Stam
    ' Initiele versie van de functie
    '************************************************* ******
    On Error GoTo ErrorHandler

    Dim strMessage As String
    Dim objRecip As Object
    Dim objMes As Object

    '************************************************* ******
    'Ontvanger is verplicht.
    '************************************************* ******
    If txtMailTo = "" Then
    strMessage = "The recipient of the mail is not valid or not given!"
    GoTo ExitFunction
    End If

    '************************************************* ******
    'Niet ingevulde parameters afhandelen.
    '************************************************* ******
    If IsMissing(txtText) Then
    txtText = ""
    End If
    If IsMissing(txtSubject) Then
    txtSubject = ""
    End If

    '************************************************* ******
    'De boodschap zelf invullen.
    '************************************************* ******
    Set objMes = objMySes.Inbox.Messages.Add
    With objMes
    .Text = txtText
    .Subject = txtSubject
    End With

    '************************************************* ******
    'De ontvanger invullen
    '************************************************* ******
    Set objRecip = objMes.Recipients.Add
    With objRecip
    .Name = txtMailTo
    .Resolve
    '.Send
    End With

    '************************************************* ******
    'En nog even versturen.
    '************************************************* ******
    objMes.Update
    objMes.Send ShowDialog:=False

    ExitFunction:
    If strMessage <> "" Then
    SendMail = strMessage
    Else
    SendMail = ""
    End If
    Exit Function

    ErrorHandler:
    SendMail = Chr(10) & Chr(13) & "Errornumber: " & CStr(Err.Number) & " "
    SendMail = SendMail & "Errormessage: " & Err.Description
    Exit Function
    End Function

    Private Sub Class_Initialize()
    '************************************************* ******
    'Bij het instantieren van het object een MAPI sessie
    'openen.
    'Let op de profilename is afhankelijk van het mail
    'programma dat gebruikt wordt.
    'Als profilename weggelaten wordt, dan wordt er, indien
    'noodzakelijk, automatisch om gevraagd.
    '************************************************* ******
    Set objMySes = CreateObject("MAPI.Session")
    If Not objMySes Is Nothing Then
    objMySes.Logon 'Als profilename niet gegeven hoeft te worden.
    'objMySes.Logon profileName:="Microsoft Exchange"
    End If

    End Sub

    Private Sub Class_Terminate()
    '************************************************* ******
    'Als het object verwijderd wordt ook de MAPI sessie
    'verwijderd.
    '************************************************* ******
    objMySes.Logoff
    End Sub

    Bart
    Software Designer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •