如何在R中发送电子邮件,读取csv并一次发送多个电子邮件? [英] How to send email in R that read csv and send multiple email at once?

查看:984
本文介绍了如何在R中发送电子邮件,读取csv并一次发送多个电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含电子邮件的CSV文件。
如何在r中发送多个电子邮件?



错误1
send.mail函数不使用data.frame值

  FUN(X [[i]],...)中的错误:
对不起,参数类型NA不明确或不支持。

错误2
函数不从read.table获取输入

  file.exists(body)中的错误:无效'file'参数

我的代码如下(仅作为示例)

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

文件< - 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)


解决方案

这里只有一个错误。使用:

 文件<  -  read.table(C:// Mehul Katara //新文件夹(2)// 131004.txt,header = TRUE,sep =;)

所以你需要更改 / // 的路径中,因为R Windows二进制行为。以上路径也可能不起作用,但在这种情况下,您需要摆脱Mehul Katara中的空格。请将您的文件放在文件路径中没有空格的另一个地方。错误1即将出现,因为错误2,一旦您修复错误2就应该去。



从文档


正文电子邮件正文为文本。如果参数体参考
现有文件位置,文件的文本将被解析为
电子邮件的正文。


所以理想情况下,您应该将函数的调用更改为:

  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)


I have CSV file that contains email. How to send multiple email in r ?

Error 1 send.mail function not taking data.frame values

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

Error 2 function not taking input from 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. Above path may also not work but in that case you need to get rid of spaces as in "MehulKatara". 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.

From the documentation

body Body of the email as text. 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)

这篇关于如何在R中发送电子邮件,读取csv并一次发送多个电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆