• Publicity: Public Only All

account-email-procs.tcl

Render and send localized account email.

Location:
packages/acs-authentication/tcl/account-email-procs.tcl

Procedures in this file

Detailed information

auth::email::send (private)

 auth::email::send -template template -user_id user_id -to to \
    -default_from default_from [ -from from ] [ -values values ]

Render an account email using the recipient's locale. The Tcl companion can set from_addr, subject and mime_type in the headers dictionary passed by reference. Use text/html for multipart delivery with a generated plain-text alternative.

Switches:
-template (required)
Name of a Tcl/ADP pair in acs-authentication/lib/email.
-user_id (required)
-to (required)
-default_from (required)
Sender used when no override is configured.
-from (optional)
Explicit sender override.
-values (optional)
Dictionary of substitution values for the message catalogs.

Partial Call Graph (max 5 caller/called nodes):
auth::local::password::RetrievePassword auth::local::password::RetrievePassword (private) auth::email::send auth::email::send auth::local::password::RetrievePassword->auth::email::send auth::password::email_password auth::password::email_password (private) auth::password::email_password->auth::email::send auth::send_email_verification_email auth::send_email_verification_email (private) auth::send_email_verification_email->auth::email::send acs_mail_lite::send acs_mail_lite::send (public) auth::email::send->acs_mail_lite::send ad_conn ad_conn (public) auth::email::send->ad_conn lang::user::locale lang::user::locale (public) auth::email::send->lang::user::locale parameter::get parameter::get (public) auth::email::send->parameter::get subsite::main_site_id subsite::main_site_id (public) auth::email::send->subsite::main_site_id

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

ad_library {
    Render and send localized account email.
}

namespace eval auth::email {}

d_proc -private auth::email::send {
    -template:required
    -user_id:required
    -to:required
    -default_from:required
    {-from ""}
    {-values {}}
} {
    Render an account email using the recipient's locale.
    The Tcl companion can set from_addr, subject and mime_type in the
    headers dictionary passed by reference. Use text/html for multipart
    delivery with a generated plain-text alternative.
    @param template Name of a Tcl/ADP pair in acs-authentication/lib/email.
    @param default_from Sender used when no override is configured.
    @param from Explicit sender override.
    @param values Dictionary of substitution values for the message catalogs.
} {
    set subsite_id [expr {[ns_conn isconnected] ? [ad_conn subsite_id] : [subsite::main_site_id]}]
    set locale [lang::user::locale -user_id $user_id -package_id $subsite_id]
    if {$from eq ""} {
        set from [parameter::get -package_id $subsite_id -parameter AccountEmailFrom -default ""]
    }
    if {$from eq ""} {
        set from $default_from
    }

    set headers [dict create from_addr $from mime_type text/plain]
    set body [template::adp_include /packages/acs-authentication/lib/email/$template \
                  [list locale $locale values $values &headers headers]]

    set from [dict get $headers from_addr]
    set subject [dict get $headers subject]
    set mime_type [dict get $headers mime_type]
    if {$from eq "" || [regexp {[\r\n]} $from] || [regexp {[\r\n]} $subject]} {
        error "Invalid account email headers"
    }
    if {$mime_type ni {text/plain text/html}} {
        error "Invalid account email content type"
    }

    acs_mail_lite::send -send_immediately -to_addr $to -from_addr $from \
        -subject $subject -body $body -mime_type $mime_type
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: