acs_mail_lite::check_bounces (private)

 acs_mail_lite::check_bounces

Defined in packages/acs-mail-lite/tcl/email-inbound-procs.tcl

Daily proc that sends out warning mail that emails are bouncing and disables emails if necessary

Partial Call Graph (max 5 caller/called nodes):
%3 acs_mail_lite::address_domain acs_mail_lite::address_domain (private) acs_mail_lite::send acs_mail_lite::send (public) ad_system_name ad_system_name (public) ad_system_owner ad_system_owner (public) ad_url ad_url (public) acs_mail_lite::check_bounces acs_mail_lite::check_bounces acs_mail_lite::check_bounces->acs_mail_lite::address_domain acs_mail_lite::check_bounces->acs_mail_lite::send acs_mail_lite::check_bounces->ad_system_name acs_mail_lite::check_bounces->ad_system_owner acs_mail_lite::check_bounces->ad_url

Testcases:
No testcase defined.
Source code:
    set package_id [apm_package_id_from_key "acs-mail-lite"]
    set max_bounce_count [parameter::get -package_id $package_id -parameter MaxBounceCount -default 10]
    set max_days_to_bounce [parameter::get -package_id $package_id -parameter MaxDaysToBounce -default 3]
    set notification_interval [parameter::get -package_id $package_id -parameter NotificationInterval -default 7]
    set max_notification_count [parameter::get -package_id $package_id -parameter MaxNotificationCount -default 4]
    set notification_sender [parameter::get -package_id $package_id -parameter NotificationSender -default "reminder@[address_domain]"]
    if { $notification_sender eq "" } {
        # Use the most specific default available
        set fixed_sender [parameter::get -package_id $package_id -parameter "FixedSenderEmail"]
        if { $fixed_sender ne "" } {
            set notification_sender $fixed_sender
        } elseif { [util_email_valid_p [ad_system_owner]] } {
            set notification_sender [ad_system_owner]
        } else {
            # Set to an email address that is required to exist
            # to avoid email loops and other issues
            # per RFC 5321 section 4.5.1
            # https://tools.ietf.org/html/rfc5321#section-4.5.1
            # The somewhat unique capitalization may be useful
            # for identifyng source in diagnostic context.
            set notification_sender "PostMastER@[address_domain]"
        }
    }

    # delete all bounce-log-entries for users who received last email
    # X days ago without any bouncing (parameter)
    db_dml delete_log_if_no_recent_bounce {}

    # disable mail sending for users with more than X recently
    # bounced mails
    db_dml disable_bouncing_email {}

    # notify users of this disabled mail sending
    db_dml send_notification_to_bouncing_email {}

    # now delete bounce log for users with disabled mail sending
    db_dml delete_bouncing_users_from_log {}

    set subject "[ad_system_name] Email Reminder"

    # now periodically send notifications to users with
    # disabled email to tell them how to re-enable the email
    set notifications [db_list_of_ns_sets get_recent_bouncing_users {}]

    # send notification to users with disabled email
    foreach notification $notifications {
        set notification_list [ns_set array $notification]
        array set user $notification_list
        set user_id $user(user_id)
        set href [export_vars -base [ad_url]/register/restore-bounce {user_id}]
        set body "Dear $user(name),\n\n Due to returning mails from your email account, \n  we currently do not send you any email from our system.\n\n  To re-enable your email notifications, please visit\n${href}"

        send -to_addr $notification_list -from_addr $notification_sender -subject $subject -body $body -valid_email
        ns_log Notice "Bounce notification send to user $user_id"

        # schedule next notification
        db_dml log_notification_sending {}
    }
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
<fullquery name="acs_mail_lite::check_bounces.get_recent_bouncing_users">
    <querytext>

       select u.user_id, u.email, u.first_names || ' ' || u.last_name as name
       from cc_users u, acs_mail_lite_bounce_notif n
       where u.user_id = n.party_id
       and u.email_bouncing_p = 't'
       and n.notification_time < current_timestamp - interval :notification_interval day
       and n.notification_count < :max_notification_count

      </querytext>
</fullquery>

<fullquery name="acs_mail_lite::check_bounces.send_notification_to_bouncing_email">
    <querytext>

       insert into acs_mail_lite_bounce_notif (party_id, notification_count, notification_time)
       select party_id, 0 as notification_count,
              current_date - (1 + cast(:notification_interval as integer)) as notification_time
        from acs_mail_lite_bounce
        where bounce_count >= :max_bounce_count

      </querytext>
</fullquery>

<fullquery name="acs_mail_lite::check_bounces.log_notification_sending">
    <querytext>

       update acs_mail_lite_bounce_notif
       set notification_time = current_date,
           notification_count = notification_count + 1
       where party_id = :user_id

      </querytext>
</fullquery>

<fullquery name="acs_mail_lite::check_bounces.delete_log_if_no_recent_bounce">
    <querytext>

       delete from acs_mail_lite_bounce
       where party_id in (select party_id
                         from acs_mail_lite_mail_log
                         where last_mail_date < current_timestamp - interval :max_days_to_bounce day)

     </querytext>
</fullquery>

<fullquery name="acs_mail_lite::check_bounces.disable_bouncing_email">
    <querytext>

       update users
       set email_bouncing_p = 't'
       where user_id in (select party_id
                         from acs_mail_lite_bounce
                         where bounce_count >= :max_bounce_count)

     </querytext>
</fullquery>

<fullquery name="acs_mail_lite::check_bounces.delete_bouncing_users_from_log">
    <querytext>

       delete from acs_mail_lite_bounce
       where bounce_count >= :max_bounce_count

     </querytext>
</fullquery>
packages/acs-mail-lite/tcl/email-inbound-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: