mailR连接被linux拒绝,但Windows拒绝 [英] mailR Connection refused from linux but not from windows

查看:73
本文介绍了mailR连接被linux拒绝,但Windows拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有mailR(用于发送电子邮件的R语言包),尝试从我的gmail帐户发送一些电子邮件.它可以在Windows上正常运行,但是从linux上可以看到以下错误.在下面的示例中,我替换了电子邮件,用户名和密码.

I have mailR (the R language package to send email) try to send some emails from my gmail account. It works flawlessly from windows, but from linux I get the errors below. In the example below I have replaced emails, usernames and passwords.

代码:

library(mailR)
emails <- c("example1@host.com")

send.emails <- function() {
  for(x in emails){
    send.mail(from = from1,
    to = x,
    subject = subject1,
    body = body1,
    smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = username,
    passwd = password, ssl = TRUE),
    authenticate = TRUE,
    send = TRUE)
  }
}

send.emails()

错误:

> send.emails()
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.NULL
java:606)
    at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout 60000;
  nested exception is:
    java.net.ConnectException: Connection refused
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)
    at javax.mail.Service.connect(Service.java:367)
    at javax.mail.Service.connect(Service.java:226)
    at javax.mail.Service.connect(Service.java:175)
    at javax.mail.Transport.send0(Transport.java:253)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 6 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:299)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:208)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
    ... 13 more
 Show Traceback

 Rerun with Debug
 Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465 

再次,我在Windows上完全没有错误,并且在Linux上运行相同的脚本时,通过电子邮件的所有错误都得到了解决.连接被拒绝...

Again, I get no error at all on windows and the emails go through, when I run the same script on linux, i get all those errors. Connection refused...

如果我可以从Linux机器上运行此脚本,那就太好了.谢谢!

If I could run this script from my linux box that would be great. Thanks!

推荐答案

好的,我有一个答案.令人惊讶的是,R在Windows而不是linux上运行不是问题(例如download.file --internet2或许多其他示例).

Ok I have an answer. Suprisingly, it's not a problem with R working on windows and not on linux (like download.file --internet2 or many other examples).

Peerguardian在Linux系统上运行,而smtp.gmail.com也在黑名单上.

Peerguardian is running on the linux system and somehow smtp.gmail.com is on a blacklist.

我已经将smtp.gmail.com列入了白名单,现在一切正常!

I've whitelisted smtp.gmail.com and now everything works!

我能够通过IP或白名单端口465列入白名单,无论哪种方式都可以.

I was able to whitelist by IP or whitelist port 465, either worked.

这篇关于mailR连接被linux拒绝,但Windows拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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