Skip to content
Prev 69448 / 398513 Next

Does R have a command for sending emails?

Fernando Saldanha wrote:
Under Linux/Unix you can use code such as the following.  This handles 
kmail and mail.

     if(mailer=='kmail') {
       tf <- tempfile()
       cat(cmd, file=tf)
       to <- paste('"', paste(to, collapse=','), '"', sep='')
       if(length(cc)) cc <- paste(' -c "', paste(cc, 
collapse=','),'"',sep='')
       if(length(bcc)) bcc <- paste(' -b "', paste(bcc, 
collapse=','),'"',sep='')
     } else {
       to <- paste(to, collapse=' ')
       if(length(cc))  cc  <- paste(paste(' -c', cc), collapse='')
       if(length(bcc)) bcc <- paste(paste(' -b', bcc),collapse='')
     }
     cmd <- if(mailer=='kmail') paste('kmail -s "', title, '"', cc,
                 bcc, ' --msg ', tf, ' ', to, sep='') else
       paste('echo -e "', cmd, '" | mail -s "',
             title, ' Reports"', cc, bcc, ' ', to, sep='')
     system(cmd)