标签: sendmailr

如何在Windows中发送带有R附件的电子邮件

我有一个从Windows机器运行的预定R脚本.

完成后,我希望此脚本自动发送附带一些日志文件的电子邮件.

使用shell()其他一些脚本可能是可能的,但我想知道R内是否有更好的解决方案.谢谢.

email r sendmailr

52
推荐指数
4
解决办法
4万
查看次数

R shiny:如何将输入数据保存到服务器或全局访问输入变量?

我正在制作一个应用程序,询问用户一些基本的调查问题.完成后,要求他们通过滑动条提供数字输入,按继续,然后生成绘图,再次询问用户输入,更新绘图等.第一个输入应该是绘图上的y1,第二个输入应该是输入应该是图上的y2,等等.但另外我想保存用户输入的数据,这样我就可以在全局的R脚本中访问它,所以可以使用sendmailR将它发送给我,这样它就可以作为文本文件下载到我的计算机上.但我无法弄清楚如何做到这一点.这是我到目前为止所拥有的.

n=10 #number of times to ask the user for input which will be stored in harv[i]
Time = seq(n)
harv = rep(0,n) #initializing vector for storage of user input at time 1 through n

############### define server logic

shinyServer(function(input, output){

  # Compute the forumla text in a reactive expression since it is 
  # shared by the output$caption and output$mpgPlot expressions
  for(i in Time){

  # generate a plot
  output$yieldplot <- renderPlot({
   harv[i] = input$harvest
   plot(Time, harv, type='p', ylim=c(0,1))
  })

 }#for …
Run Code Online (Sandbox Code Playgroud)

r rstudio sendmailr shiny

21
推荐指数
1
解决办法
8933
查看次数

在Windows上使用sendmailR

我正在尝试使用以下代码在Windows上运行sendmailR:

## Not run: 
from <- "<tal.galili@gmail.com>" # sprintf("<sendmailR@\\%s>", Sys.info()[4])
to <- "<tal.galili@gmail.com>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
         control=list(smtpServer="ASPMX.L.GOOGLE.COM."))
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

Error in socketConnection(host = server, port = port, blocking = TRUE) : 
  cannot open the connection
In addition: Warning message:
In socketConnection(host = server, port = port, blocking = TRUE) :
  smtp.gmail.com tal.galili@gmail.com:statisfun:25 cannot be opened
Run Code Online (Sandbox Code Playgroud)

这里的答案为Linux提供了解决方案,我将非常感谢Windows用户的建议.

谢谢.

email gmail smtp r sendmailr

20
推荐指数
2
解决办法
1万
查看次数

使用SendMailR将数据框作为电子邮件正文中的表格发送

我正在尝试使用SendMailR发送数据帧.我可以将它作为附件发送,格式相当合理.但是,我想在电子邮件正文中发送数据帧.我尝试了capture.output,print,sprintf,但我甚至无法将格式关闭.

例如,我尝试了以下语法

for (i in 1:nrow(df)){
 MSG = c(MSG,rownames(df)[1],as.character(unlist(df[i,])),'\n')
} 
MSG = sprintf('%-10s',MSG)
sendmail(from,to,subject,msg = list(MSG,attachment1,attachment2 ... ))
Run Code Online (Sandbox Code Playgroud)

换句话说,我认为可能需要将我的数据帧转换为带有/ n和sprintf('s-10%')等的格式并将其存储在MSG中.有人能指出我正确的方向吗?

r sendmailr

8
推荐指数
2
解决办法
1万
查看次数

mailR:如何在电子邮件中将rmarkdown文件作为正文发送?

如何rmarkdown使用R在电子邮件中将生成的文档作为正文发送?

我已成功尝试knitrmailR,但是当使用(新)rmarkdown-package 生成html-report时,它失败了.

library(mailR)
send.mail(
  from = "FROM@gmail.com",
  to = "TO@gmail.com",
  subject = "MyMail",
  html = T,
  inline = T,
  body = "my_report.html",
  smtp = list(host.name = "smtp.gmail.com", port = 465,
    user.name = "USERNAME", passed = "PASSWORD", ssl = T),
  authenticate = T,
  send = T
)
Run Code Online (Sandbox Code Playgroud)

错误:

org.apache.commons.mail.EmailException: Building the MimeMessage failed
    at org.apache.commons.mail.ImageHtmlEmail.buildMimeMessage(ImageHtmlEmail.java:110)
    at org.apache.commons.mail.Email.send(Email.java:1436)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: java.io.IOException: Cant …
Run Code Online (Sandbox Code Playgroud)

email r sendmailr r-markdown

6
推荐指数
1
解决办法
3964
查看次数

将gvis对象(存储为HTML的图像)嵌入到mailR-R中的内联中

我正在使用googleVisChart并希望将gvis对象(存储为HTML的图像)嵌入到内联使用mailR包中.

我有以下代码从我的服务器发送邮件 -

library(mailR)
send.mail(from = "admin_xxx@apsmail.xx.xxx.xx",
          to = c("first.second@jba.com"),
          subject = paste("Batch Job Stats on",now),
          body = paste("Dear Sir/Madam,<br><br>

                       Please find below the image",".<br><br>",
                       "<img src=\"D:/xx/Batch_Processing/Batch_Processing_Run/Rplot1.png\">",".<br><br>"
          ),
          html = TRUE,inline = TRUE,         
          smtp = list(host.name = "xxxx01.xxx.xxx.xx"),
          authenticate = FALSE,
          send = TRUE)
Run Code Online (Sandbox Code Playgroud)

上面的代码完全正常 - 我嵌入了一个图像(存在于我的服务器的D盘中)

现在我googleVis用来创建一个图表并将它们存储在html文件中.(出现在我服务器的D盘中)

Gauge <-  gvisGauge(CityPopularity,
options=list(min=0, max=800, greenFrom=500,
greenTo=800, yellowFrom=300, yellowTo=500,
redFrom=0, redTo=300, width=400, height=300))
plot(Gauge)

print(Gauge, tag="chart", file="test1.html")
Run Code Online (Sandbox Code Playgroud)

所以现在我的问题是我无法嵌入我的.html文件(使用上面的代码创建test1.html)来发送电子邮件,其中googleVis包含嵌入在邮件描述主体中的图表图像.(我无法保存gvis对象-Chart …

email smtp sendmail r sendmailr

6
推荐指数
1
解决办法
468
查看次数

列宽与使用sendmailr从R发送的pander表中的表数据不对齐

我正在使用'pander'和'sendmailr'软件包在电子邮件正文中发送一个小数据框,而不是附件.我想将它发送到一个Gmail帐户.

我很接近,但是列标题不会像他们在Rstudio中那样与电子邮件主体中的列本身对齐 - 例如 - 列标题太宽而不能与它们下面的数据列对齐.

似乎问题是在各种电子邮件客户端中压缩破折号和空格的方式(我在gmail,yahoo和hotmail中通过网络和OS X Mavericks附带的电子邮件客户端尝试了这一点).我能够通过转到"首选项"并选中标记为"使用固定宽度字体显示纯文本消息"的框来解决我的OS X电子邮件客户端中的问题,但我希望它可以在多个设备上工作,具有多个许多同事的客户等等,所以我想知道是否有一种不涉及全球电子邮件设置的方式.

以下是重现问题的代码:

library(sendmailR) # for emails from R
library(pander) # for table-formatting that does not require HTML

results <- head(iris)
pander(results) # widths look great so far...
a = pandoc.table.return(results)
strsplit(a, "\n") # widths still look great...

panderOptions('table.split.table', Inf) # show all columns on same line

msg_content <- mime_part(
  pandoc.table.return(results, style = "multiline")
)

# I'm using my own gmail address for email_from and email_to
sendmail(from = email_from,
         to = email_to, …
Run Code Online (Sandbox Code Playgroud)

r sendmailr pander

5
推荐指数
1
解决办法
608
查看次数

如何消除R中的emayili包中的错误

“emayili”包中出现 R 错误。

# Create a message object..
# Add addresses for the sender and recipient.
# Add a subject.
# Add a text body.
to_send<- envelope(to = "xxx@gmail.com",
           from = "xxx@gmail.com",
           subject = "ALERT",
           text="xxx")
smtp<- server(host = "smtp.gmail.com",
          port = 465,
          username = "xxx@gmail.com",
          password = "password form less secure apps setting")
Run Code Online (Sandbox Code Playgroud)

我的说法是错误的, Error: Request failed after 5 attempts 我实际上用在线 SMTP 测试工具测试了几次,看来它可以工作。我检查了一下rlang::last_error(),输出是:

<error/purrr_error_rate_excess>
Request failed after 5 attempts
Backtrace:
 1. emayili:::smtp(msg, verbose = TRUE)
 2. purrr:::send_mail(...) …
Run Code Online (Sandbox Code Playgroud)

sendmail r sendmailr

5
推荐指数
0
解决办法
440
查看次数

创建持久的多行字符串

我想为R中的变量分配一个多行字符串,以便我可以稍后调用该变量.当我尝试paste("line 1", "line 2", sep = "\n")我得到"line 1\nline 2".当我尝试时cat("line 1", "line 2", sep = "\n"),我得到了所需的输出,但这是输出不是持久的(cat()返回类型的对象None).我尝试使用多行字符串的原因是我需要通过sendmailR邮件正文中的SMTP服务器(和包)发送查询结果(而不是作为附件).

newline r sendmailr

4
推荐指数
1
解决办法
2912
查看次数

sendmailR - 附加多个收件人

我已成功设法实现sendmailR功能,以便向一个收件人发送一条消息.

您知道是否可以将相同的消息发送给该功能中的多个收件人?CC'ing的一种形式?

如果不是,我认为唯一的方法是循环一个变量,这通常是可以的,但对于我当前的代码将导致循环内的循环并使事情公平,希望不必要的复杂

我无法在文档中看到任何表明这样的功能的内容 - > http://cran.r-project.org/web/packages/sendmailR/sendmailR.pdf

感谢您的帮助,我会继续测试,看看在此期间是否有解决方法!

sendmail r sendmailr

4
推荐指数
1
解决办法
2887
查看次数

从R发送电子邮件 - 当计划脚本在Windows中失败时

我有一个Rscript文件(Main_Script.R)Main_Script.R,它每30分钟在Windows任务计划程序中作为一个重要的工作运行.在- 我有大约13个脚本,每30分钟运行一次.

我希望从R发送电子邮件 - 每当迭代失败或被骚扰时.我正在使用sendMailR包 - 我在SO中看过一篇文章how to send email with attachment from R in windows- 关于如何从R Windows发送emqil.

但我不确定 - 如何发送email automatically with the error message- 当计划任务迭代失败或受到攻击时.

我的Main_Script.R- 有source13个代码.

source(paste(rootAddress,"Scripts/Part1.R",sep =''))
source(paste(rootAddress,"Scripts/Part2.R",sep =''))
:
:
:
:
source(paste(rootAddress,"Scripts/Part13.R",sep =''))
Run Code Online (Sandbox Code Playgroud)

我的Sheduled任务看起来像下面的日志文件

"D:\xxx\R-3.0.2\bin\x64\Rscript.exe" "D:\xx\Batch_Processing\Batch_Processing_Run\Scripts\Main_Test.R" >> "D:\XXX\Batch_Processing\Batch_Processing_Run\error.txt" 2>&1
Run Code Online (Sandbox Code Playgroud)

更新:

当脚本遇到错误时 - 它应该触发电子邮件 - 使用erorr meassge和脚本名称或编号 - 来表示13个脚本中的哪一个失败并发送到邮件ID.

email r sendmailr

3
推荐指数
1
解决办法
1233
查看次数

如何将数据框转换为表格以作为电子邮件正文发送

我有这个数据框:

library(sendmailR)
library(pander)

dput(s)
structure(list(Description = c("ServerA", "ServerB", "ServerC", 
"ServerD", "ServerE", "ServerF"), Value = c("2", "2", "100", 
"100", "80", "20")), .Names = c("Description", "Value"), row.names = c(NA, 
6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

我想把这个数据框放在一个漂亮的表格中,然后通过电子邮件发送给一些人。

我用 pandoc 尝试过,但表格看起来很简单:

 t<-pandoc.table.return(s, caption="Server CPU Utilization")

    from <- "user@example.com"
    to <- c("end_users@example.com")
    subject <- paste(Sys.time()," Servers CPU utilization")
    body <- t                
    mailControl=list(smtpServer="mailhost.example.net")

    sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以将数据框格式化为漂亮的表格以作为电子邮件发送?表格必须在电子邮件正文中,而不是作为附件。

r sendmailr pander

1
推荐指数
1
解决办法
4118
查看次数

标签 统计

r ×12

sendmailr ×12

email ×5

sendmail ×3

pander ×2

smtp ×2

gmail ×1

newline ×1

r-markdown ×1

rstudio ×1

shiny ×1