【问题标题】:Sending an email from R using the sendmailR package使用 sendmailR 包从 R 发送电子邮件
【发布时间】:2020-10-01 08:16:31
【问题描述】:

我正在尝试使用 sendmailR 包从 R 发送电子邮件。下面的代码在我的 PC 上运行时运行良好,并且我收到了电子邮件。但是,当我用我的 macbook pro 运行它时,它会失败并出现以下错误:

library(sendmailR)
from <- sprintf("<sendmailR@%s>", Sys.info()[4])
to <- "<myemail@gmail.com>"
subject <- "TEST"
sendmail(from, to, subject, body,
    control=list(smtpServer="ASPMX.L.GOOGLE.COM"))

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) :
  ASPMX.L.GOOGLE.COM:25 cannot be opened

关于为什么这可以在 PC 上运行,而不是在 Mac 上运行的任何想法?我在两台机器上都关闭了防火墙。

【问题讨论】:

  • 您是否尝试过其他端口,即 587?
  • @wkmor1 我尝试在 sendmailR 控制参数中设置端口 587,但它似乎仍然在 25 以上进行通信。有什么想法吗?

标签: macos email r


【解决方案1】:

您可以通过命令行发送电子邮件吗?

所以,首先,启动一个终端,然后

$ echo “Test 123” | mail -s “Test” user@domain.com

查看/var/log/mail.log,或者更好地使用

$ tail -f /var/log/mail.log 

在您发送电子邮件时在不同的窗口中。如果你看到类似的东西

... setting up TLS connection to smtp.gmail.com[xxx.xx.xxx.xxx]:587
... Trusted TLS connection established to smtp.gmail.com[xxx.xx.xxx.xxx]:587:\
    TLSv1 with cipher RC4-MD5 (128/128 bits)

那么你成功了。否则,这意味着您必须配置您的邮件系统。我在 Gmail 中使用 postfix 已有两年了,我从来没有遇到过问题。基本上,您需要从这里获取 Equifax 证书 Equifax_Secure_CA.pemhttp://www.geotrust.com/resources/root-certificates/。 (他们之前使用的是 Thawtee 证书,但去年发生了变化。)然后,假设您使用的是 Gmail,

  1. /etc/postfix 中创建relay_password 并像这样输入一行(使用正确的登录名和密码):

    smtp.gmail.com login@gmail.com:password
    

    然后在终端中,

    $ sudo postmap /etc/postfix/relay_password 
    

    更新 Postfix 查找表。

  2. 将证书添加到/etc/postfix/certs,或者你喜欢的任何文件夹中,然后

    $ sudo c_rehash /etc/postfix/certs/ 
    

    (即,使用 Openssl 重新散列证书)。

  3. 编辑/etc/postfix/main.cf,使其包含以下几行(如果需要,调整路径):

    relayhost = smtp.gmail.com:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/relay_password
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = may
    smtp_tls_CApath = /etc/postfix/certs
    smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
    smtp_tls_session_cache_timeout = 3600s
    smtp_tls_loglevel = 1
    tls_random_source = dev:/dev/urandom
    
  4. 最后,只需重新加载 Postfix 进程,例如

    $ sudo postfix reload 
    

    start/stop 的组合也可以)。

您可以为 SMTP 选择不同的端口,例如465。 在没有TLS 的情况下仍然可以使用SASL(上述步骤基本相同),但在这两种情况下,主要问题是您的登录信息在计划文本文件中可用......另外,如果你想使用您的 MobileMe 帐户,只需将 Gmail SMTP 服务器替换为 smtp.me.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多