我正在尝试从我的Shiny应用程序发送邮件。我已经为邮件的地址,主题和正文创建了文本输入框。当我在textInput框中输入的是单个电子邮件ID时,应用程序会发送邮件。当我添加第二个电子邮件ID时,它会失败。但是,当我尝试从RStudio而不是闪亮的应用程序运行它时,相同的代码,我能够发送电子邮件。如何让我的textInput正确解析电子邮件ID,以便mailR向他们发送邮件?
我目前的代码:
library(shiny)
library(mailR)
ui =fluidPage(
fluidRow(
div(id = "login",
wellPanel(title = "Mail your report",
textInput("to", label = "To:", placeholder = "To:"),
textInput("sub","Subject:"),
textInput("msg","Message:"),
actionButton("mailButton",label = "Send mail")
)
))
)
server = function(input, output, session) {
observeEvent(input$mailButton,{
isolate({
send.mail(from = "myemail@gmail.com",
to = input$to,
subject = input$sub,
body = input$msg,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "myemail@gmail.com", passwd = "mypasword", ssl = TRUE),
authenticate = TRUE,
html = TRUE,
send = TRUE)
})
})
}
runApp(list(ui = ui, server = server))
我收到以下错误:
Listening on http://127.0.0.1:3499
javax.mail.internet.AddressException: Illegal address in string ``email1@gmail.com, email2@gmail.com''
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:114)
NULL
Warning: Error in : AddressException (Java): Illegal address
Stack trace (innermost first):
83: <Anonymous>
82: signalCondition
81: doWithOneRestart
80: withOneRestart
79: withRestarts
78: message
77: value[[3L]]
76: tryCatchOne
75: tryCatchList
74: tryCatch
73: .jTryCatch
72: .valid.email
71: send.mail
64: isolate
63: observeEventHandler [#3]
1: runApp
ERROR: [on_request_read] connection reset by peer
答案 0 :(得分:2)
试试这个,假设电子邮件之间的分隔符是分号:
to = unlist(strsplit(input$to, ";", fixed = TRUE))