2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Stephen Overall -
Number of replies: 29

Hi:

I can't seem to get my fresh Moodle 2.0.2+ installation to send the "Welcome" email (containing new user's username and automatically-generated temporary password) to new users created through the CSV Upload Users method.

I have had the same problem all weekend with my fresh Moodle 2.0.1+ installation.

I have used this CSV Upload Users method successfully in previous Moodle 1.9.5-10 installations. Emails were sent without problem.

I am using exactly the same CSV file setup that worked fine for me in Moodle 1.9.10. I'm using the same Authentication methods (Manual Accounts and No Login enabled) and Enrolment methods (Manual Enrolments, Flat File (CSV), Course Meta Link, Guest Access, Cohort Sync enabled) in 2.0.2 that worked for me in 1.9.10 (excepting the new Course Meta Link and Cohort Sync, of course). Password policy is enabled.

In my CSV file, I have left the Password field empty and on the Upload Users Preview page I set the New User Password field to "Create password if needed". All of this should trigger Moodle to upload the new users, generate random temporary passwords for them, and then send the "Your account has been created" emails when triggered by cron.php (which I have run manually 20-25 times to ensure cron.php does get a chance to do its job). Doing all this is what has worked for me many times before in 1.9.5-10.

But in 2.0.1 and 2.0.2 no "Welcome, your new account has been created" emails are sent to my new test users. Their user accounts are created fine. The database "emailstop" field in the mdl_user table is set to "0" so the email addresses are enabled, I believe.

The new user "password" fields are set to this string: 2e40bdf6d00c1776effe40ceff3420e0

If I go to my Moodle login screen and click the "Forgot your username or password?" link and fill in one of the new user usernames, then Moodle correctly sends the two confirmation emails required to reset the password. I can then login as this new user. So Moodle is able to send emails to the correct addresses.

Am I missing something here? Is it something I am or am not doing? Or is it a bug? I've searched the forums and Tracker but don't find others with exactly this issue and experience.

Thanks.

Average of ratings: -
In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Stephen Overall -

Also I should mention that in Plugins > Enrolments > Flat File (CSV) I have ticked the checkboxes "Notify students by email", "Notify teachers by email", and "Notify admins by email" to send those emails.

In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Stephen,

I've had a look at the code, and I think it's a bug in the upload users code.

I've changed these lines (around line 618 of admin/uploadusers.php):


if (!$isinternalauth) {
$user->password = 'not cached';
$upt->track('password', 'not cached');
} else {
$user->password = hash_internal_user_password($user->password);
}


to these:


if (!empty($user->password)) {
if (!$isinternalauth) {
$user->password = 'not cached';
$upt->track('password', 'not cached');
} else {
$user->password = hash_internal_user_password($user->password);
}
}


and it has started working (after several cron.php runs, to trigger the relevant part of the code).

Can you confirm that this fixed the problem for you too? Thanks in advance.

Saludos.
Iñaki.
In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Bill W -

I am using Moodle 2.1.1+ (Build: 20110803) and I cannot for the life of me find where to make these modifications so new accounts get emailed their login credentials when I upload new users to a course

Have been using 1.9.x for years and that has always sent the notification on account creation

Thanks in advance!

 

In reply to Bill W

not sending welcome/password emails to CSV uploaded new users

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Bill - the settings are in site admin>plugin>enrolment>flat file.

But  -anyone - does this work? I have just tried this on 2.1( and run cron) and not got any emails -yet emails are sent out from forums, messages etc..

In reply to Mary Cooch

Re: not sending welcome/password emails to CSV uploaded new users

by Iván Melgrati -

Dear Mary:

In order for emails to get sent you tick the checkboxes "Notify students by email", "Notify teachers by email", and "Notify admins by email" on Plugins > Enrolments > Flat File (CSV). Also, on some versions (I'm pretty sure on 2.1 this has been fixed but you may have to fix it by yourself), some hand-coding had to be done in order to force Moodle send emails. See here for more information.

Kind regards,

Iván

In reply to Iván Melgrati

Re: not sending welcome/password emails to CSV uploaded new users

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Thanks Ivan. Yes - I had those ticked and I am on 2.1 but wasn't getting the emails. I saw the hand-coding post -maybe I will go in and try it though I don't normally codesmile -it is odd that it doesn't work for me when it is meant to be fixed in 2.1smile

In reply to Bill W

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
[Edit: all of this refers to the creation of new users with no password specified in the CSV field]

There's no need to make the modifications I proposed in my old message. If you use 2.0.x or 2.1.x newer than 2011.03.01, the modifications from Petr that are part of MDL-26564 take care of the issue.

I have just tried with a test install of Moodle 2.1.1+ (Build: 20110916) and Moodle 2.0.4+ (Build: 20110916), and both send the welcome/password emails as expected (after several manual runs of cron, as the creation of the passwords and email sending doesn't trigger in every cron run).

Saludos.
Iñaki.
In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by sachin suryavanshi -

Hi,

I want send one mail once user register his/her account in moodle.

 

Regrads

Sachin

In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by manmohan singh -

Thanks Iñaki

 

 This code working fine.

----

Thanks & Regards:

manmohan

In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Aryashree Pritikrishna -

Hi,

I have installed Moodle 2.4.1, currently I have issue with email sending. When I created a new user or enroll an user for course they are not getting any Welcome message .

When I have tried for forgot password, the emails are working fine.

Please help me to get out from this issue.

Thank you in advance!

--
Aryashree Pritikrishna

In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Amber Lee Mogg -

Hi Iñaki,

This code worked for me as well!  Thank you very much for sharing it smile

In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

For reference, this (and one big revamp including many fixes/improvements) of the upload users facility is in progress @ MDL-26564

Ciao smile

Average of ratings: Useful (1)
In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by andrea giorgini -

Hey guys,

please I need help. I have the same need: if I upload users or just create them manually one by one as admin, I'd like the users to receive an email, with the steps to begin. I thought this should be just easy, but I cannot find the way to achieve that. Nor I have those menu items "Notify XXX by e-mail". I'm working with Moodle 2.0.2+.

What am I doing wrong?

Thanks a lot

Andrea

In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Jordan Wolff -

Have we found a solution to this? I am using 2.0.X, I uploaded a CSV, not a Flat FIle CSV, and I want an email sent to the "students" I uploaded via the csv with their user name and password.

 

I tired to do the solution Iñaki suggested but cannot seem to located the the code grouping together in that file.

I would think this would be a standard feature and cannot figure out why the it is not sending out the emails. I am even leaving out the the password in my CSV file to have moodle generate a password and hopefully email the "student" but no such luck.

In reply to Jordan Wolff

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Any more comments? I am trying on a 2.0.3 so it should be fixed to work but the students don't get emails (nor do I the admin)  I can't see where I am going wrong. Also - I looked at Iñaki's code but I couldn't see the exact same lines around 618 of my filemixed

In reply to Mary Cooch

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Mary,

Petr's work on MDL-26564 changed so many things in that file that neither the line number nor the surrounding code look like the code I posted back in February.

But I think we may be talking about different things here (or perhaps different expectations smile). Upload users will (currently) only send emails in these cases when creating new users:

  • no password is specified in the csv file, and 'Create password if needed' option is selected
  • a password is specified in the csv file, but it doesn't comply with the configured password policy.

When updating existing users, an email will be sent when the password specified in the csv file doesn't comply with the configured password policy

That's what I gather by looking at the code.

Saludos. Iñaki.

Average of ratings: Useful (1)
In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Thanks for that clarification. Well - obviously mine doesn't work then because I am testing option 1 above and no emails are being sent outmixed Emails work for forums and messages however. I run cron several times and still no joy.

In reply to Mary Cooch

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Mary,

when you run cron.php, does it ever print 'checking for create_password' and then 'creating passwords for new users'? If it does, and no emails arrive to new users, can you add the following debugging lines to lib/cronlib.php to see if Moodle is even trying to send anything?

Look for the block of lines that like these (around line 284 in 2.0.4) and add the marked lines:


//
// generate new password emails for users
//
mtrace('checking for create_password');
if ($DB->count_records('user_preferences', array('name'=>'create_password', 'value'=>'1'))) {
mtrace('creating passwords for new users');
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,
u.lastname, u.username,
p.id as prefid
FROM {user} u
JOIN {user_preferences} p ON u.id=p.userid
WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
if (empty($newusers)) { // <<<---- Add this line here
mtrace('Oops! $newusers is empty!'); // <<<---- Add this line here
} // <<<---- Add this line here
foreach ($newusers as $newuser) {
// email user
if (setnew_password_and_mail($newuser)) {
unset_user_preference('create_password', $newuser);
set_user_preference('auth_forcepasswordchange', 1, $newuser);
} else {
trigger_error("Could not create and mail new user password!");
}
}
$newusers->close();
}
else { // <<<---- Add this line here
mtrace('No need to create passwords for new users'); // <<<---- Add this line here
} // <<<---- Add this line here



Btw, admins don't get a copy of the emails sent to new users (you mentionned the admin wasn't getting the emails either).

Saludos.
Iñaki.
In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Thanks - I will try this in the light of day. On a 2.0.3 that I have, it works fine. However, on a 2.0.4 which as far as I can tell is set up the same - it does not work. So I will take a look.

In reply to Mary Cooch

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Nigel Mitchell -

I have a list of 105 new users for a Moodle (2.1.1) that I would like to enrol in bulk. I have done this before with a .csv file in which I allocated passwords to the users, and had no problem. With this batch I want Moodle to generate the passwords. I have uploaded a small .csv file with some test enrolments and no email has been sent to those dummy users (I used my own alternate email addresses).

I don't actually know how to run cron.php, but even if I did from what appears above there seems to be no guarantee that would make any difference.

I'd be grateful for any advice or assistance. I would really prefer not to have to generate the passwords and emails all myself.

Thanks

Nigel

In reply to Nigel Mitchell

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Meredith Cushman -

In Moodle 1.9, if you omit the password field in your .csv file and select 'Create password if needed' when you use 'Upload users' function, moodle creates the password for each person and emails it to the email addresses listed in the .csv file when cron runs.  

In Moodle 1.9, doing a search for 'cron' (in the search box at the bottom of the Site Administration block) returns the string to run cron from your webbrowser.  Fill in your own info for the site url.  You may need a password if you set one on this link:   http://site.example.com/admin/cron.php  We are hosted and cron's behavior/timing is not clear to me.  But it does eventually run and send the emails.  I've tested with alternate email addresses.

Meredith

 

 

In reply to Meredith Cushman

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Nigel Mitchell -

Thanks, Meredith, for your advice about how to manually run cron.php.

I can do that now, and I see cron manually creating passwords, but it still does not send out the emails to my users.

I am using 2.1.3 which might be the problem. I cannot see a ticket on the tracker about this. Should I create one, or has anyone else got any other ideas? 

In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by John Lovelady -

Dear Inaki,

I'm having the same issues described in this thread, however the task "send_new_user_passwords" is missing from cron all together, and from my scheduled task page in moodle.

I've also tried to run the task scripts via CLI, returning the following errors:

"php5 send_new_user_passwords_task.php" :  

PHP Fatal error:  Class 'core\task\scheduled_task' not found in /home/onlinei6/public_html/courses/lib/classes/task/send_new_user_passwords_task.php on line 29


"php5 schedule_task.php --list" :

PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1 in /home/onlinei6/public_html/courses/admin/tool/task/cli/schedule_task.php on line 64

PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1 in /home/onlinei6/public_html/courses/admin/tool/task/cli/schedule_task.php on line 64

PHP Parse error:  parse error, unexpected T_STRING in /home/onlinei6/public_html/courses/admin/tool/task/cli/schedule_task.php on line 64



Do you know how to approach a solution? I'm running moodle version 2.8.1 (Build: 20141113) and my hosted server is running PHP 5.5

Thank you for your time

In reply to Iñaki Arenaza

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Steve M -

Inaki

I think MDL-26564 may fix my problem too (no email sent to new enrolled users) but I can't access this in Tracker. I have created a Jira account but it says I don't have permissions to search for this. Maybe Tracker requires admin activation? 

The same problem occurs in 2.02 and 2.1.2.

Does anyone know if there's an update available to fix this issue? Thanks.

In reply to Steve M

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Peter Munro -

Hi (No Welcome or Password emails)

 

I have the same problem.  I know the email server works because the server support guys said so.  My server support guys tell me the problem is in the mail logs.  I am not able to access the mail logs with SSH.  I do not know ssh.

Can I pay some to fix this so I can move forward.

Peter

In reply to Stephen Overall

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Navin Lallan -

Good day,


I recently installed version 2.7 and am attempting to upload users via a FLAT CSV File however unfortunately the email with credentials is not being forwarded to the students.


Can anyone suggest what may be the cause?

Confirming I have selected the fields to send to students, teacher etc.


Thank you for your assistance,

Navin

In reply to Navin Lallan

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Johannes Prischl -

Hi,

unfortunately I can't offer any help, but I can confirm the problem - see also my previuos thread "Task "send new user password" not working?"

I wonder if somebody has reported this as a bug?

Johannes

In reply to Johannes Prischl

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by C Li -

After uploading the csv file, try going to http://your-site/moodle/admin/cron.php to manually run cron.

If you see the line "Scheduled task failed: Send new user passwords,Authentication plugin {$a} not found", go visit https://tracker.moodle.org/browse/MDL-46589 for a workaround. 

Hope it helps.

Average of ratings: Useful (1)
In reply to C Li

Re: 2.0.1-2+ not sending welcome/password emails to CSV uploaded new users

by Johannes Prischl -

 I had already discovered that and fixed it, but thanks anyway for responding!

Johannes