-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssendmail.m
51 lines (45 loc) · 1.58 KB
/
ssendmail.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [ status ] = ssendmail(subject, message_file, varargin)
% securely (meaning my password is not stored in clear text in matlabs
% config file) sends email.
% with my msmpt recipient, subject, message_file
%
% [ status ] = ssendmail(subject, message, varargin)
%
% ssendmail('to', '[email protected]'); Default is
% [email protected]. For multiple reciepients, this should
% be a cell array of email addresses.
%
% ssendmail('attachment', 'somefile.ext'). Currently not
% implemented.
p = inputParser;
p.addParameter('to', '[email protected]');
p.addParameter('attachments', '');
parse(p, varargin{:});
to = p.Results.to;
attachments = p.Results.attachments;
% msg = sprintf(['From: [email protected]\n'...
% 'Subject: %s: %s\n',...
% '%s\n'], date(), subject, message);
subject = sprintf('%s: %s', date, subject);
sndmail = '/usr/bin/msmtp -a arnold-rabraker';
if ~iscell(to)
to = {to};
end
for to_ = to
% cmd = sprintf('echo "%s" |%s %s', msg, sndmail, to_{1});
cmd = sprintf('cat %s|./sendattach.sh -t %s -s "%s" ', message_file,...
to_{1}, subject);
cmd = add_attachments(cmd, attachments);
status = system(cmd);
end
end
function cmd = add_attachments(cmd, attachments)
if ~isempty(attachments) % need this?
for attach = attachments
% k=1:length(attachments)
% attach = attachments{k}
% keyboard
cmd = sprintf('%s -a %s', cmd, attach{1});
end
end
end