Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用mailR向不同的收件人发送不同的内容_R - Fatal编程技术网

如何使用mailR向不同的收件人发送不同的内容

如何使用mailR向不同的收件人发送不同的内容,r,R,我正在尝试向不同的收件人发送不同的内容,但所有收件人都会收到所有内容。有什么帮助吗 library(mailR) msg<- data.frame(recipients=c("first@mail.com","second@mail.com","third@mail.com"), messages=c("firstmsg","secondmsg","thirdmsg")) for ( i in msg$recipients) { for (j

我正在尝试向不同的收件人发送不同的内容,但所有收件人都会收到所有内容。有什么帮助吗

library(mailR)
msg<- data.frame(recipients=c("first@mail.com","second@mail.com","third@mail.com"),
                 messages=c("firstmsg","secondmsg","thirdmsg"))

for ( i in msg$recipients)  
{  
  for (j in msg$messages)  {
    send.mail(from="myemail@mail.com",
              to= i,  
              body =  j,
              subject = "subject",
              encoding = "utf-8",  
              smtp= list(host.name = "smtp.gmail.com", port = 465, 
                         user.name = "myemail@mail.com", passwd = "mypassword", ssl = TRUE),
              authenticate = TRUE,  send = TRUE,  attach.files=NULL,  debug = FALSE)
  }
}
库(mailR)

msg您正在使用一个双循环,它将针对循环中的每个
i
值遍历
j
的每个值。一种方法是使用列表索引:

msg<-data.frame(recipients=c("first@mail.com","second@mail.com",
"third@mail.com"),messages=c("firstmsg","secondmsg","thirdmsg"))

for i in 1:nrow(msg)  
{  
send.mail(from="myemail@mail.com",
to= msg$recipients[i],  
body =  msg$message[i],
subject = "subject",
encoding = "utf-8",  
smtp= list(host.name = "smtp.gmail.com", port = 465, 
user.name = "myemail@mail.com", passwd = "mypassword", ssl = TRUE),
authenticate = TRUE,  send = TRUE,  attach.files=NULL,  debug = FALSE)
}

msgwel欢迎来到我们的网站!