From bd80f8b360f2d93d02bec1313c3248df4fa92bfb Mon Sep 17 00:00:00 2001 From: k1o0 Date: Mon, 31 Jul 2023 10:40:27 +0100 Subject: [PATCH] Send emails one at a time using sendmail --- +ww/generate.m | 23 +++++++++++++++++------ run_safe.m | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/+ww/generate.m b/+ww/generate.m index 4ed6376..e74a138 100644 --- a/+ww/generate.m +++ b/+ww/generate.m @@ -75,9 +75,12 @@ function generate(nDays, varargin) % use 2 for usual weekends, 3 for long weekends etc. [nDays, fail] = ww.getNumDays(); if fail && ~test - sendmail(admins, 'Action required: Days may be incorrect',... - ['Weekend water script failed to determine whether there are '... - 'any upcoming Bank holidays. Investigate.']); + recipients = admins; + for iRecipient = 1:numel(recipients) + sendmail(recipients{iRecipient}, 'Action required: Days may be incorrect',... + ['Weekend water script failed to determine whether there are '... + 'any upcoming Bank holidays. Investigate.']); + end end end @@ -98,12 +101,20 @@ function generate(nDays, varargin) if ~isempty(skipped) && ~test msg = sprintf(['The following mice have no weekend water information:\n\r %s\n\r',... - 'This occured because a weight for today was not inputted into Alyx before 6pm. \n',... + 'This occured because a weight for today was not inputted into Alyx before 6pm. \n',... 'Please manually write the weight and water to be given on the paper sheet upstairs. ',... 'For the days you will be training, please write ''PIL''.'], strjoin({skipped.subject}, '\n')); [~,I] = intersect({users.username}, {skipped.user}); - sendmail(vertcat(users(I).email, admins),... - 'Action required: Weekend information missing', msg); +% sendmail(vertcat(users(I).email, admins),... +% 'Action required: Weekend information missing', msg); + % Single-instance message headers must be included only once in a + % message (RFC 5322). Multiple recipients to sendmail duplicates 'To' + % field, so we'll send one email per recipient instead. + recipients = vertcat(users(I).email, admins); + for iRecipient = 1:numel(recipients) + sendmail(recipients{iRecipient}, 'Action required: Weekend information missing', msg); + end + end % print nicely, 'water.png' will be saved in the current folder diff --git a/run_safe.m b/run_safe.m index 484c863..005e0dc 100644 --- a/run_safe.m +++ b/run_safe.m @@ -2,6 +2,7 @@ try ww.generate; status = 0; -catch +catch e + warning(e.identifier, 'ERROR: %s', e.message); status = 1; end \ No newline at end of file