proc emailNotification {logType objectId userLogin receiverLogin logText} {
    if {![::mailer::isActive]} {
        return
    }
    set server [::mailer::smtpServer]

    if {$receiverLogin eq ""} {
        return
    }
    switch $logType {
        "action_give_obj" {
            set action {$initiatorName hat Ihnen die Datei zur pers\u00f6nlichen\
                    Bearbeitung zugewiesen.}
        }
        "action_forward_obj" {
            set action {$initiatorName hat Ihrer Gruppe $receiverLogin die\
                    Datei zur Bearbeitung weitergeleitet.}
        }
        "action_commit_obj" -
        "action_sign_obj" {
            set action {$initiatorName hat Ihrer Gruppe $receiverLogin die\
                    Datei zur Pr\u00fcfung vorgelegt.}
        }
        "action_reject_obj" {
            set action {$initiatorName hat die Datei zur\u00fcckgewiesen.}
        }
        default {
            return
        }
    }

    # extract objType, objClass and path of the object
    set keys [list objType objClass path validFrom]
    mset $keys [eval [list obj withId $objectId mget] $keys]

    # do not send email for images and templates.
    if {[lsearch -exact {document publication generic} $objType] == -1} {
        return
    }
    # do not send email for certain objClasses
    set classesWithoutNotification {}
    if {[lsearch -exact $classesWithoutNotification $objClass] != -1} {
        return
    }

    # newsletter infos holen
    if {$objClass eq "Newsletter"} {
        set newsTitle ""
        set name [user withLogin $userLogin get realName]
        set newsletterTitle [obj withId $objectId get title]
        set begin [obj withId $objectId get ip_newsletterHeader]
        set end [obj withId $objectId get ip_newsletterFooter]

        append news [obj withId $objectId get ip_newsletterNews]
        set action {Hallo Frau/Herr $name,}
    }

    # send a mail to ...
    if {[groupWithNameExists $receiverLogin]} {
        set receiverLogins [groupWithNameGet $receiverLogin users]
    } elseif {[userWithLoginExists $receiverLogin]} {
        set receiverLogins [list $receiverLogin]
    } else {
        ::mailer::logWarning "Cannot determine user or group '$receiverLogin'"
        return
    }

    set incompleteEmails [list]
    set receivers [list]
    foreach l $receiverLogins {
        if {[set email [userWithLoginGet $l email]] == ""} {
            lappend incompleteEmails $l
            continue
        }
        lappend receivers $email
    }
    if {[llength $incompleteEmails] > 0} {
        ::mailer::logWarning [format {The following users\
                have no email entry: %s} [join $incompleteEmails ", "]]
    }
    if {[llength $receivers] < 1} {
        ::mailer::logWarning {Could not determine any receiver email address}
        return
    }
    set to [join $receivers ","]

    set initiatorName [userWithLoginGet $userLogin realName]
    if {$initiatorName eq ""} {
        set initiatorName $userLogin
    }
    set from [userWithLoginGet $userLogin email]
    if {$from eq ""} {
        set from $userLogin
    }

    set action [subst $action]
    # assemble the email body: newsletter / normale Benachrichtigung
    if {$objClass eq "Newsletter"} {
        set signature "Ihr Playland Team"

        set date [string range [systemConfig formatDate [string range $validFrom 0 7]] 0 9]
        if {$logText ne ""} {
            set logText "\n$logText"
        }

        set previewInfo ""
        set export_path "http://localhost:8080/PM"
        set index "/index.html"

        foreach i $news {
            set path2 [obj withId $i get path]
            append previewInfo "

+++ " [obj withId $i get title] " +++
    " [obj withId $i get ip_abstract] "
    \[...mehr\] unter " $export_path$path2$index
        }

        set body [subst {>$newsletterTitle<

$action
$begin

Folgende interessante News erwarten Sie auf unserer Homepage:
$previewInfo

$end

>>> $signature}]
    } else {
        set guiLink [guiUrl $path]
        set title [obj withId $objectId editedContent get title]
        if {$logText ne ""} {
            set logText "\n$logText"
        }

     set body [subst {
        $action

        Pfad  : $path
        Titel : $title
        $logText

        Sie k\u00f6nnen die Datei mit folgendem Link erreichen:
        $guiLink
        }]
    }

    ::mailer::logMessage [format\
            {Action: %s; From: %s; To: %s; Path: %s}\
            $logType $from $to $path]
    if {[catch {
        if {$objClass eq "Newsletter"} {
            set subject "\[Infopark CMS Fiona\] Benachrichtigung f\u00fcr einen Newsletter"
        } else {
            set subject "\[Infopark CMS Fiona\] Benachrichtigung f\u00fcr eine Datei"
        }
        set headers [list "X-NPS-Workflow-Action" $logType]
        ::mailer::sendTextMail $body $subject $from $to $headers
    } msg]} {
        ::mailer::logWarning [format "delivery failed: %s\nStack: %s" $msg $::errorInfo]
    }
}
