+
+ # If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
+ if ( C4::Context->preference("AutoEmailNewUser") ) {
+ #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
+ my $emailaddr = $patron->notice_email_address;
+ # if we manage to find a valid email address, send notice
+ if ($emailaddr) {
+ eval {
+ my $letter = GetPreparedLetter(
+ module => 'members',
+ letter_code => 'WELCOME',
+ branchcode => $patron->branchcode,,
+ lang => $patron->lang || 'default',
+ tables => {
+ 'branches' => $patron->branchcode,
+ 'borrowers' => $patron->borrowernumber,
+ },
+ want_librarian => 1,
+ ) or return;
+
+ my $message_id = EnqueueLetter(
+ {
+ letter => $letter,
+ borrowernumber => $patron->id,
+ to_address => $emailaddr,
+ message_transport_type => 'email'
+ }
+ );
+ SendQueuedMessages({ message_id => $message_id });
+ };
+ }
+ }
+
+ # Notify library of new patron registration
+ my $notify_library = C4::Context->preference('EmailPatronRegistrations');
+ if ($notify_library) {
+ $patron->notify_library_of_registration($notify_library);
+ }
+