在OSX上通过R解决方法发送Outlook电子邮件

时间:2018-04-04 00:06:51

标签: r rstudio rdcomclient

我在整个网站上看过,但一直未能找到答案。

我需要使用R通过我的工作Outlook电子邮件发送电子邮件。它必须来自Outlook,而不是其他任何地方。

问题是,我使用的计算机是OSX,因此RDCOMClient将无效。

编辑:试过这个并且它不起作用。

sender<-"myemail@outlook.com"
recipients<-c("myemail@outlook.com")
send.mail(from = sender, to = recipients,
          subject = "Test",
          body = BodyOfMessage,
          smtp = list(host.name = "smtp-mail.outlook.com"),
          authenticate = FALSE,
          html = TRUE,
          send = TRUE)Does anyone have a workaround? 

导致了这个错误:

  

org.apache.commons.mail.EmailException:将电子邮件发送给   以下服务器失败:smtp-mail.outlook.com:25 at   org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)at at   org.apache.commons.mail.Email.send(Email.java:1437)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   RJavaTools.invokeMethod(RJavaTools.java:386)引起:   com.sun.mail.smtp.SMTPSendFailedException:530 5.7.57 SMTP;客户是   未经过身份验证,以便在MAIL FROM期间发送匿名邮件   [BN6PR19CA0117.namprd19.prod.outlook.com]

     

在   com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2202)     at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1693)     在   com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)     在javax.mail.Transport.send0(Transport.jaNU​​LL va:254)at   javax.mail.Transport.send(Transport.java:124)at   org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)... 6   更多错误:EmailException(Java):将电子邮件发送到以下内容   服务器失败:smtp-mail.outlook.com:25

2 个答案:

答案 0 :(得分:1)

所以,你不一定会通过你的Outlook客户端发送这个,这就是Outlook的全部内容。您可能希望允许您编写的R脚本和使用的库是电子邮件客户端。我使用mailR取得了很大的成功。有些人喜欢sendmailR来发送消息。他们都有自己的优势。如果您从主机运行大量脚本,则您的电子邮件管理员可能允许未经身份验证的发送。或者您可以在脚本中进行身份验证。 例如:

library(mailR)
#################
# Generate Spam #
#################
BodyOfMessage <- paste("<html><body><p>Hello,</p><p>This is an email message.</p>
                      <hr>
                      <p>The second table is a list of users that need to be toggled in the system, by adding them to the correct securitygroup.</p>
                      <p>", toggle.these.people, "</p>
                      <p>Scott</p></body></html>")
#mailR
    sender<-"fromwho@fromyou.org"
    recipients<-c("emailtosendto@email.com")
    send.mail(from = sender, to = recipients,
    subject = paste("Blah. Created: today.", sep = ""),
    body = BodyOfMessage,
    smtp = list(host.name = "smtp.exchangeserver.org"),
    authenticate = FALSE,
    html = TRUE,
    attach.files = CSVFileNameIs,    
    send = TRUE)

答案 1 :(得分:0)

这是我使用的,它对我来说很好。

library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email 
outMail = OutApp$CreateItem(0)
## configure  email parameter 
outMail[["To"]] = "ryanshuell@gmail.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
## send it                     
outMail$Send()