如何从R中的联系人表单发送电子邮件

如何从R中的联系人表单发送电子邮件,r,curl,shiny,shiny-server,blastula,R,Curl,Shiny,Shiny Server,Blastula,我在一个闪亮的应用程序中实现了一个联系人表单,并使用包“blastula”及其函数“smtp_send”将消息发送到发件人提供的电子邮件地址。代码是: library(shiny) library(blastula) library(shinyAce) ui = fluidPage( fluidPage( wellPanel( textInput("from" , "From:" , value="...@..."), textInput("to"

我在一个闪亮的应用程序中实现了一个联系人表单,并使用包“blastula”及其函数“smtp_send”将消息发送到发件人提供的电子邮件地址。代码是:

library(shiny)
library(blastula)
library(shinyAce)

ui = fluidPage(
  fluidPage(
    wellPanel(
      textInput("from"   , "From:"   , value="...@..."),
      textInput("to"     , "To:"     , value="...@..."),
      textInput("subject", "Subject:", value="This is the subject"),

      p("Message", style="font-weight: bold;"),
      aceEditor("msg", value="This is the message"),
      br(),
      actionButton("send", "Send email!")
    )
  )   
)

server <- function(input, output)
{
  observe(
  {
    if(is.null(input$send) || input$send==0) return(NULL)

    Email = compose_email(body = input$msg, header = NULL, footer = NULL, title = NULL)
    Credentials = creds_anonymous(host = "smtp...", port = 25, use_ssl = TRUE)

    smtp_send(email = Email, to = input$to, from = input$from, subject = input$subject, credentials = Credentials)
  })
}

shinyApp(ui = ui, server = server)
库(闪亮)
库(囊胚)
图书馆(新亚斯)
ui=fluidPage(
流动摄影(
井面板(
textInput(“from”,“from:”,value=“…@…”),
textInput(“to”,“to:”,value=“…@…”),
textInput(“主题”,“主题:”,value=“这是主题”),
p(“消息”,style=“font-weight:bold;”),
aceEditor(“msg”,value=“这是消息”),
br(),
操作按钮(“发送”、“发送电子邮件!”)
)
)   
)

服务器我提取了我用我的应用程序处理电子邮件问题的方式——gmail方式适用于outlook one,我不确定,因为我有一段时间没有检查它了

用你自己的方式替换细节,gmail方式首先被评论

代码如下,忽略中间的斯洛文尼亚语。它们也是一些检查,当有人可以发送和电子邮件,如果地址是正确的,等等

这可能会有帮助

编辑:必须定义问题,并且您的电子邮件地址应为gmail.com

library(shiny)
# library (RDCOMClient)
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_241/') 
library(mailR)
library(shinythemes)
library(shinyjs)

ui = fluidPage(
  useShinyjs(),
  fluidPage(
    br(),
    fluidRow(
      column(12,align="center",
             h1(icon("envelope", lib = "font-awesome"))),
      br(),
      column(12,align="center",
             textInput("telo", "Problem statement","", width = "400px",
                       placeholder= "obvezno izpolnite!"),
             br(),
             textInput("kontakt","Your working email - necessary!","",
                       placeholder = 'ime.priimek@gmail.com'),
             helpText("Test email= Thorin@gmail.si"),
             actionButton("send", "Send",icon("fas fa-arrow-up", lib = "font-awesome")),
             br())),
    br(),
    fluidRow(
      column(12,
             br()))
  )



)   


server <- function(input, output,session)
{
  disable("send")
  ###################################################################################### pošlji email, telo strani
  testek11<-function(failed = FALSE) {
    modalDialog(
      title="",
      fluidRow(column(12,align="center",
                      "SEND.")),
      br(),
      easyClose = FALSE,
      footer=fluidRow(column=12,align="center",
                      modalButton("OK",icon=icon("fas fa-check-circle"))
      )
    )
  } 

  observeEvent(input$send,{
    #showModal(testek21())
    shinyjs::disable("send")
    shinyjs::disable("nazaj2")
    shinyjs::disable("telo")
    shinyjs::disable("kontakt")


    ## gmail way
    Sys.sleep(2)

    # send.mail(from = paste(input$username,"@domain.com",sep=""),
    #           to = c("test99@gmail.com"),
    #           subject = paste("Aplikacija NNP: Problem:",input$kontakt,sep=" OD "),
    #           body =  paste(input$telo,input$username,sep=" // OD // "),
    #           smtp = list(host.name = "smtp.gmail.com", port = 465,
    #                       user.name = "test99@gmail.com",
    #                       passwd = "pass", ssl = TRUE),
    #           authenticate = TRUE,
    # send = TRUE)


    ## outlook way -- possibly outdated

    # OutApp <- COMCreate("Outlook.Application")
    # outMail = OutApp$CreateItem(0)
    # outMail[["To"]] = "ur email adrres to where you want to send -- you can make it reactive"
    # outMail[["subject"]] = "subject"
    # outMail[["body"]] <- "body"
    # outMail$Send()
    # 
    shinyjs::enable("send")
    shinyjs::enable("nazaj2")
    shinyjs::enable("telo")
    shinyjs::enable("kontakt")
    showModal(testek11())
    updateTextInput(session,"telo",value="",placeholder = "Obvezno izpolnite!")
    updateTextInput(session,"kontakt",value="",placeholder = 'ime.priimek@gmail.si')
  })

  ##### enabling maile pa to kdaj lahko klikne send

  mailhelp <- reactiveValues(hmm=FALSE)
  mailhelp2 <- reactiveValues(hmm2=FALSE)



  observeEvent(input$telo,{
    if(input$telo != ""){
      isolate(mailhelp$hmm <- TRUE)
    }
    else{
      isolate(mailhelp$hmm <- FALSE)
    }
  })

  observeEvent(input$kontakt,{
    if(grepl("@gmail.com",input$kontakt) |grepl("@GMAIL.CON",input$kontakt) ){
      isolate(mailhelp2$hmm2 <- TRUE)
    }
    else{
      isolate(mailhelp2$hmm2 <- FALSE)
    }
  })

  observe({
    if(mailhelp2$hmm2 & mailhelp$hmm){
      shinyjs::enable("send")
    }
    else{
      shinyjs::disable("send")
    }
  })
}

shinyApp(ui = ui, server = server)
库(闪亮)
#图书馆(RDCOMClient)
Sys.setenv(JAVA_HOME='C:\\Program Files\\JAVA\\jre1.8.0_241/'))
图书馆(邮递)
图书馆(shinythemes)
图书馆(shinyjs)
ui=fluidPage(
useShinyjs(),
流动摄影(
br(),
fluidRow(
列(12,align=“center”,
h1(图标(“信封”,lib=“font-awesome”),
br(),
列(12,align=“center”,
textInput(“telo”,“问题陈述”,“width=”400px“,
占位符=“OBVEZONO izpolnite!”),
br(),
textInput(“kontakt”,“您的工作电子邮件-必要!”,“”,
占位符='输入法。priimek@gmail.com'),
helpText(“测试电子邮件=Thorin@gmail.si"),
操作按钮(“发送”、“发送”图标(“fas fa向上箭头”,lib=“font-awesome”),
br()),
br(),
fluidRow(
第(12)栏,
br()))
)
)   

服务器谢谢!我还想知道为什么使用囊胚包中的函数还不起作用。囊胚的优点是你不需要Java。我对囊胚一无所知,因为我从来没有厌倦过它。公平地说,这个应用程序也有两年的历史了,我相信现在有更好的解决方案——但只要它能工作,就不要使用它:D。。。