Skip to content

Commit

Permalink
Send emails one at a time using sendmail
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Jul 31, 2023
1 parent 62c9a7e commit bd80f8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 17 additions & 6 deletions +ww/generate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion run_safe.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
try
ww.generate;
status = 0;
catch
catch e
warning(e.identifier, 'ERROR: %s', e.message);
status = 1;
end

0 comments on commit bd80f8b

Please sign in to comment.