Sending Outlook Mail from R via a Perl Script -
original problem: how pass arguments in string r script perl script via system() command 1 flag may have 0 or more arguments.
for example: "email.perl -t " p1@email.com; p2@email.com;" -c " p3@email.com; p4@email.com;" -s "subject line" -b "body text" -f c:/file.txt"
i figured out. toolic on right path, had pass ; after each name work. below working code who's interested.
r function:
sendperlmail <- function(email.to, email.cc=na, email.sub=na, email.body=na, email.file=na) { command <- 'perl ..\\..\\email.perl -t "' for(to.p in email.to) {command <- paste0(command, paste0(' ', to.p, ';'))} command <- paste0(command, '" -c "') for(cc.p in email.cc) {command <- paste0(command, paste0(' ', cc.p, ';'))} command <- paste0(command, paste0('" -s ', email.sub)) command <- paste0(command, paste0(' -b ', email.body)) command <- paste0(command, paste0(' -f ', email.file)) return(system(command, intern=t, invisible=f)) } perl script:
#!/usr/bin/perl -w use mail::outlook; use getopt::std; %opts; getopts('t:c:s:b:f:', \%opts); $outlook = new mail::outlook(); $msg = $outlook->create(); if(!$opts{t}) {die} else {$msg->to($opts{t});} if($opts{c} ne 'na') {$msg->cc($opts{c});} if($opts{s} ne 'na') {$msg->subject($opts{s});} if($opts{b} ne 'na') {$msg->body($opts{b});} if($opts{f} ne 'na') {$msg->attach(type => 'text/plain', path => "/", filename => $opts{f});} $msg->send;
have pass ; after each email address.
command <- 'perl ..\\..\\email.perl -t "' for(to.p in email.to) {command <- paste0(command, paste0(' ', to.p, ';'))}
Comments
Post a Comment