Need to check list of emails sent to a particular user sent to user in the past

Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
Number of replies: 10

Hello Developers,

I need to check all automated mails(any email) sent by moodle.  I am not able to find the sent mail.

In Site Administrators --> Reports --> Logs I see list of events like User logged in, course viewed.

Arn't there any ways I check email sent.

Please suggest me.

 

Attachment Screenshot from 2019-12-09 13-05-01.png
Average of ratings: -
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you have access to them, you would be better to use mail logs.

If the object is *prove* that they got the email then that's really what you want. The user could have disabled notifications for a period, for example.
In reply to Howard Miller

Re: Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
Hello Howard,

Thank your for you response smile.

Actually I need to check list of mails sent to a user by moodle, day wise or weekly. From logs I am not able to get email status like when I signup a mail is sent to that user, but no log entry is there

Yes I have to write a script that tells number of mails gone to a user eg. Signup mail, course enrolled mail or whatever default mail is sent by moodle on some event. I need to track mail based on date

Please guide me.
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
I found a table named mdl_logstore_standard_log. There only list of failed emails I see. I am not able to find list of successful emails sent by moodle sad
Attachment Screenshot from 2019-12-09 18-34-41.png
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
Can someone please guide how to proceed. I am really stuck in this issue.

Thank you
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Sounds to me like you are involved in a dispute in which you need evidence that certain e-mails have been sent. If so, the only thing you can provide is the logs of the SMTP server to which Moodle delivers e-mail. It is set under Site administration > Server > Email > Outgoing mail configuration.
In reply to Visvanath Ratnaweera

Re: Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
Hello Vishvanath,
Sorry for seeing this thread late.

How can I see the list of emails sent or logs here from moodle Outgoing mail.

At present my requirement is not to check whether mail sent is success or failed in moodle. I just need to know list of all possible default emails moodle sends at any case like by default on sign up a mail shoots. Similarly in what other cases mail is sent (default mails). May another mail is sent when user enrols the course.

Thank you for your time. Please suggest me.
Really appreciating smile
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
It is not Moodle, which sends the mails out rather the so called SMTP server. Therefore the logs depend on what the SMTP server is. If you take a common Linux server like Debian running Postfix as an example, the logs are in /var/log/mail.log. The shell command 'tail -f /var/log/mail.log' will update the logs in "iive".

If the logs are no accessible, you can add a debug line in to Moodle code, around phpmailer. As a reminder: Don't start changing Moodle code unless you know what you are doing!
In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Ken Task -
Picture of Particularly helpful Moodlers

Won't find what you need in one place ...

Successful Emails or Messages?  And just because systems say sent doesn't mean user reads.  Case in point ... the 'nag' Emails from your moodle about new vesions of moodle available ... but you have routed to your trash or turned it off.   End user could do same!

Moodle doeesn't really track true e-mail.
Messages it kinda knows about:

For a 24 hour period:
Query (below is from command line) and outputs to a 24hrmessages.txt file:

mysql -u root -p'password' -e "use moodledb;select userid,action,other,ip,realuserid,origin,ip from mdl_logstore_standard_log WHERE (timecreated > UNIX_TIMESTAMP(NOW() - INTERVAL 24 HOUR) and other like '%messageid%');"> 24hrmessages.txt;cat 24hrmessages.txt


Renders:

userid    action    other    ip    realuserid    origin    ip
9    sent    a:2:{s:9:"messageid";i:18638;s:8:"courseid";s:1:"3";}    NULL    NULL    cli    NULL
12293    viewed    a:1:{s:9:"messageid";i:18638;}    NULL    NULL    cli    NULL
1071    sent    a:2:{s:9:"messageid";i:18639;s:8:"courseid";s:1:"3";}    NULL    NULL    cli    NULL
9    viewed    a:1:{s:9:"messageid";i:18639;}    NULL    NULL    cli    NULL
1071    sent    a:2:{s:9:"messageid";i:18640;s:8:"courseid";s:3:"106";}    NULL    NULL    cli    NULL
9    viewed    a:1:{s:9:"messageid";i:18640;}    NULL    NULL    cli    NULL
9    sent    a:2:{s:9:"messageid";i:18641;s:8:"courseid";s:3:"112";}    NULL    NULL    cli    NULL
12268    viewed    a:1:{s:9:"messageid";i:18641;}    NULL    NULL    cli    NULL
1071    sent    a:2:{s:9:"messageid";i:18642;s:8:"courseid";s:3:"112";}    NULL    NULL    cli    NULL
9    viewed    a:1:{s:9:"messageid";i:18642;}    NULL    NULL    cli    NULL
1071    sent    a:2:{s:9:"messageid";i:18643;s:8:"courseid";s:3:"118";}    NULL    NULL    cli    NULL
9    viewed    a:1:{s:9:"messageid";i:18643;}    NULL    NULL    cli    NULL
1071    sent    a:2:{s:9:"messageid";i:18644;s:8:"courseid";s:3:"211";}    NULL    NULL    cli    NULL
8691    viewed    a:1:{s:9:"messageid";i:18644;}    NULL    NULL    cli    NULL


Translation ... user id 9 is an admin level user that communicates with users in site via Moodle messages.  One can see course ID's above.

IP addresses are null because this shows activity of a cron job (cli) for distributing messages.

Obviously, one will need to look up other userid info to see who.  And yet other tables for messages to see what.  Leave that sluething to you! smile

*** If users preferences exclude using Email for such communications, no email is sent.

Real Email sent ... CentOS 6 Moodle/phpmailer with Senmail:
in /var/log/

[root@classroom log]# ls -l maillog*
-rw------- 1 root root  72546 Dec 11 07:21 maillog
-rw------- 1 root root 221483 Nov 17 03:51 maillog-20191117
-rw------- 1 root root 193469 Nov 24 03:45 maillog-20191124
-rw------- 1 root root 178961 Dec  1 03:41 maillog-20191201
-rw------- 1 root root 209007 Dec  8 03:38 maillog-20191208

Logs are rotated.  maillog above is current active log.

clip of current maillog above:

Dec 11 07:21:30 classroom sendmail[22954]: xBBCLUgc022954: from=admins@email, size=1276, class=0, nrcpts=1, msgid=<5df0df4a2bf7e4.79463360@moodle.server.fqdn, relay=apache@localhost
Dec 11 07:21:30 classroom sendmail[22955]: xBBCLUuU022955: from=<admins@email>, size=1544, class=0, nrcpts=1, msgid=<5df0df4a2bf7e4.79463360@moodle.server.fqdn, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Dec 11 07:21:30 classroom sendmail[22954]: xBBCLUgc022954: to="X student" <sudents@hotmail.com.addreess>, ctladdr=admins@email (48/48), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31276, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (xBBCLUuU022955 Message accepted for delivery)

Obvously you'd not have access to sudents@hotmail.com.addreess nor the logs of hotmail server.

Ain't no easy button here!   Dig in and have 'fun sluething'!

'SoS', Ken


In reply to Ken Task

Re: Need to check list of emails sent to a particular user sent to user in the past

by Amir Mustafa -
Hello Ken,

Thank you for your response. I need to check list of default emails. At present I just need to report all possible mail moodle sends. I have to give info about emails only (not Messages).

I was thing of a way to check list of email_to_users() fired in moodle and for which  case?

Thank you for your replying smile

In reply to Amir Mustafa

Re: Need to check list of emails sent to a particular user sent to user in the past

by Ken Task -
Picture of Particularly helpful Moodlers

*EMail* only ...

There's a thing called "logwatch'.
Once a day parses server logs and sends a report to root user.
One of the logs is maillog and on one of the serves I maintain I use postfix with
Sendgrid as SMTP server.  It's hosted on Google Compute Engine which does not
allow any port 25 out or in.
So the flow for anything from Moodle that involves EMail is:

Moodle -> Postfix -> Sendgrid uses TLS and a port other than port 25.

Here's the postfix log parsing clip:

logwatch@centos-7-2.localdomain via sendgrid.net
   
Dec 22, 2019, 9:17 PM (11 hours ago)
   
to root, me

################### Logwatch 7.4.0 (03/01/11) ####################
       Processing Initiated: Mon Dec 23 03:17:03 2019
       Date Range Processed: yesterday
                             ( 2019-Dec-22 )
                             Period is day.
       Detail Level of Output: 10
       Type of Output/Format: mail / text
       Logfiles for Host: centos-7-2
##################################################################


--------------------- Postfix Begin ------------------------

****** Summary *************************************************************************************

   5.551K  Bytes accepted                               5,684
   5.551K  Bytes sent via SMTP                          5,684
   5.551K  Bytes delivered                              5,684
========   ==================================================

       1   Accepted                                   100.00%
--------   --------------------------------------------------
       1   Total                                      100.00%
========   ==================================================

       1   Removed from queue
       1   Delivered
       1   Sent via SMTP

****** Detail (1) ******************************

1   Delivered -------------------------------------------------------------------------------
       1      centos-7-2.localdomain

       1   Sent via SMTP ---------------------------------------------------------------------------
       1      domain

=== Delivery Delays Percentiles ============================================================
                    0%       25%       50%       75%       90%       95%       98%      100%
--------------------------------------------------------------------------------------------
Before qmgr       1.30      1.30      1.30      1.30      1.30      1.30      1.30      1.30
In qmgr           0.02      0.02      0.03      0.03      0.03      0.03      0.03      0.03
Conn setup        0.00      0.09      0.18      0.28      0.33      0.35      0.36      0.37
Transmission      0.00      0.02      0.04      0.06      0.07      0.08      0.08      0.08
Total             1.30      1.40      1.50      1.60      1.66      1.68      1.69      1.70
============================================================================================

---------------------- Postfix End -------------------------

Other wise you would need to find something that parses maillogs ...

Locate your servers maillogs.  Take a look yourself with command given you to watch those in realtime.

https://www.google.com/search?client=firefox-b-1-d&q=email+parser

'SoS', Ken