Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendmailR - Attached more than one recipient

I have successfully managed to implement the sendmailR function to send one message to one recipient.

Do you know if it is possible to send that same message to multiple recipients within the function? A form of CC'ing?

If not I think the only way is to loop round on a variable, which would normally be okay but for my current code would result with a loop within a loop and make things fairly and hopefully unnecessary complex

I cant see anything in the documentation that would appear to indicate functionality like this --> http://cran.r-project.org/web/packages/sendmailR/sendmailR.pdf

Thanks for any help, I will keep testing to see if there is a work around inm the meantime!

like image 900
Methexis Avatar asked Feb 15 '23 06:02

Methexis


1 Answers

In the source code for sendmail it states...

if (length(to) != 1) 
        stop("'to' must be a single address.")

So this leaves you with several options (all of which are loops).The execution time of a loop compared to sending the email will be negligible. A couple of options are:

Option 1

Use Vectorize to vectorise the to argument of sendmail, allowing you to supply a character vector of email addresses to send to...

sendmailV <- Vectorize( sendmail , vectorize.args = "to" )
emails <- c( "[email protected]" , "[email protected]" )
sendmailV( from = "[email protected]" , to = emails )

Option 2

Using sapply to iterate over the a character vector of email addresses applying the sendmail function each time...

sapply( emails , function(x) sendmail( to = "[email protected]" , to = x ) ) 
like image 99
Simon O'Hanlon Avatar answered Feb 23 '23 02:02

Simon O'Hanlon