Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

email template

Questions related to installing, updating, setting up and configuring
kev1n
nuBuilder Team
Posts: 4470
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 498 times
Contact:

Re: email template

Unread post by kev1n »

I also fixed the "Update User AS" SQL.
sietwolt
Posts: 38
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 7 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Thanks. Both updates done. Looking forward to your further instructions.
Han
kev1n
nuBuilder Team
Posts: 4470
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 498 times
Contact:

Re: email template

Unread post by kev1n »

Next step: Verify that a welcome email is sent when a new user is created.
sietwolt
Posts: 38
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 7 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Thanks!! A welcome email is sent now. Great !! Best to delete the old nuwelcome email templates?
Can i now set a welcome email to a category of users ( which field in the new user addition?)
kev1n
nuBuilder Team
Posts: 4470
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 498 times
Contact:

Re: email template

Unread post by kev1n »

Now you can set up your different welcome email templates.

1. Open the template nu_send_welcome_email_template and click Clone.
2. Enter a code (e.g. send_welcome_email) and set a group (e.g. manager).
3. Modify the subject, body, etc., and save the template.

Next, repeat the process for another group:

1. Open the template nu_send_welcome_email_template again and click Clone.
2. Enter a code (e.g. send_welcome_email — either the same as in step 1 or a different one) and set a group (e.g. sales).
3. Modify the subject, body, etc., and save the template.

Note: To allow multiple templates with the same code, run this SQL update first:

Code: Select all

UPDATE zzzzsys_object
SET sob_all_validate = 1
WHERE zzzzsys_object_id = 'nu635294e972f5f54';
Old welcome templates can be deleted if they are no longer required.

Next instructions will follow when done :)
sietwolt
Posts: 38
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 7 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Ok . Changes and sql done. Waiting for your next instructions
kev1n
nuBuilder Team
Posts: 4470
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 498 times
Contact:

Re: email template

Unread post by kev1n »

The last step is to create your own "Send Welcome email" procedure.

1. Open the Procedure template nu_send_welcome_email_template.
2. Click Clone (the code field will automatically change to nu_send_welcome_email).
3. Overwrite the existing code by pasting the code below and adapt the code to use your ids etc.

Code: Select all

// Retrieve Information about the user
$user = nuUserSavedInfo();
$accessLevelId = $user["access_level_id"];

// Decide which template to use based on access level

// <<<<<<<< Use your  access level ids, template name and group names <<<<<<<<<<<<<<<<<<<<<<<

switch ($accessLevelId) {

    case '2660a0de8f28a50': // Manager access level id
        $template = nuGetEmailTemplateData("send_welcome_email", '', 'manager'); // E.g. "manager" is what you entered in the group field
        break;

    case '2660a0de8f28a52': // sales access level id
        $template = nuGetEmailTemplateData("send_welcome_email", '', 'sales');
        break;

    default: // Fallback (if access level not recognized)
        $template = nuGetEmailTemplateData("send_welcome_email", '', 'default');
        break;
}

if ($template == false) {
    nuDisplayError('Unknown email template!');
    return;
}

$sendResult = sendEmailFromTemplate($template);
if ($sendResult[0] != true) {
    nuDisplayError($sendResult[1].'<br>'.$sendResult[2]);
}


// Sends an email message using an email template.
function sendEmailFromTemplate($template) {

    $body = str_replace('#'.'NUBUILDER_URL'.'#', nuGetHttpOrigin() , $template['body']);

    $params = array(
        'to'      => $template['to'],
        'cc'      => $template['cc'],
        'bcc'     => $template['bcc'],
        'body'    => nl2br($body),
        'subject' => $template['subject']
    );

    // Replace all Hash Cookies
    foreach ($params as $key => $value) {
        $params[$key] = nuReplaceHashVariables($value);
    }

    return nuSendEmail($params);
}

4. Save it

The corresponding access level IDs can be retrieved as follows:

1. Open an access level.
2. Press Ctrl+Shift+M (or go to Options Menu - Form Info).
3. The displayed Record ID is the access level ID.
sietwolt
Posts: 38
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 7 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Great thanks for the help. Excuses my ignorance: how can i combine a new user and a specific welcome email using the recordID
kev1n
nuBuilder Team
Posts: 4470
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 498 times
Contact:

Re: email template

Unread post by kev1n »

Can you elaborate a bit? I don’t quite understand what you mean by combining a new user and a welcome email with the recordID
sietwolt
Posts: 38
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 7 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

I'll try.
In emailtemplates is a field " category". I thought that adding an user it would be possible in that userform to fill in also the categoryname in a field and that as a consequence for the new user the intended welcome-email would be send
-----------------------------------------------------------------------------------------------
According your instructions: the recordID of the accesslevel 'vrijwilliger' = 67e3ff43a45adc2.
In the cloned emailtemplate I adjusted the code with this accesslevel as follows:

case '67e3ff43a45adc2': // vrijwilliger access level id
$template = nuGetEmailTemplateData("send_welcome_email", '', 'vrijwilliger'); // E.g. "vrijwilliger" is what you entered in the group field
break;

The name 'vrijwilliger' entered in the group field.
Entering a new user as 'vrijwilliger' results not in the adjusted template.

What am I doing wrong?
Post Reply