简体   繁体   English

如何在R中发送读取csv的电子邮件并立即发送多封电子邮件?

[英]How to send email in R that read csv and send multiple email at once?

I have CSV file that contains email. 我有包含电子邮件的CSV文件。 How to send multiple email in r ? 如何在r中发送多个电子邮件?

Error 1 send.mail function not taking data.frame values 错误1 send.mail函数未获取data.frame值

Error in FUN(X[[i]], ...) : 
  Sorry, parameter type `NA' is ambiguous or not supported.

Error 2 function not taking input from read.table 错误2函数不从read.table中获取输入

Error in file.exists(body) : invalid 'file' argument

My code as below (credentials as an example only) 我的代码如下(凭证仅作为示例)

temp <- read.csv("E:/OneDrive/M.Tech/temp.csv",header = FALSE)
m <- data.frame(temp)
email <- m[2,14]
rollno <- m[2,1]

file <- read.table("C:/Mehul Katara/New folder (2)/131004.txt",header =  TRUE,sep = ";")

send.mail(from = "user@gmail.com",
          to = email,
          subject = rollno,
          body = file,        
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "user@gmail.com", passwd = "password", ssl = TRUE),              
          authenticate = TRUE,
          send = TRUE)

There is just one error with this. 这只有一个错误。 Use: 采用:

file <- read.table("C://Mehul Katara//New folder (2)//131004.txt",header =  TRUE,sep = ";")

So you need to change / in path to // because of R windows binary behavior. 因此,由于R windows二进制行为,您需要将路径更改为/ // Above path may also not work but in that case you need to get rid of spaces as in "Mehul 上面的路径也可能不起作用,但在这种情况下你需要摆脱空间,如“Mehul Katara". Please put your file in another place where there is no space in filepath. Error 1 is coming just because of error 2 and should go as soon as you fix error 2. Katara“。请将您的文件放在文件路径中没有空格的另一个地方。错误1正好因为错误2而来,并且应该在您修复错误2后立即执行。

From the documentation 从文档中

body Body of the email as text. body作为文本的电子邮件正文。 If the parameter body refers to an existing file location, the text of the file is parsed as body of the email. 如果参数主体引用现有文件位置,则将文件的文本解析为电子邮件的主体。

so ideally you should change call of function to something like: 理想情况下,您应该将函数调用更改为:

send.mail(from = "user@gmail.com",
          to = email,
          subject = rollno,
          body ="C://Mehul_Katara//New_folder_(2)//131004.txt"
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "user@gmail.com", passwd = "password", ssl = TRUE),              
          authenticate = TRUE,
          send = TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM