使用sendmailR包从R发送电子邮件 [英] Sending an email from R using the sendmailR package

查看:618
本文介绍了使用sendmailR包从R发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sendmailR 包。当我在PC上运行它时,下面的代码工作正常,我收到了电子邮件。但是,当我用我的macbook pro运行它时,它会失败,出现以下错误:

I am trying to send an email from R, using the sendmailR package. The code below works fine when I run it on my PC, and I recieve the email. However, when I run it with my macbook pro, it fails with the following error:

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?我在两台机器上关闭了防火墙。

Any ideas as to why this would work on a PC, but not a mac? I turned the firewall off on both machines.

推荐答案

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

Are you able to send email via the command-line?

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

So, first of all, fire up a Terminal and then

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

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

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

在不同的窗口中。如果您看到像

in a different window while you send your email. If you see something like

... 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.pem http://www.geotrust.com/resources/root-certificates/ 。 (他们在去年之前使用了Thawtee证书,但是在去年更改了之后)。然后,假设您使用Gmail,

then you succeeded. Otherwise, it means you have to configure you mailing system. I use postfix with Gmail for two years now, and I never had have problem with it. Basically, you need to grab the Equifax certificates, Equifax_Secure_CA.pem from here: http://www.geotrust.com/resources/root-certificates/. (They were using Thawtee certificates before but they changed last year.) Then, assuming you used Gmail,


  1. 创建 relay_password / etc / postfix 中,并放置一行(使用正确的登录名和密码):

  1. Create relay_password in /etc/postfix and put a single line like this (with your correct login and password):

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

然后在终端,

$ sudo postmap /etc/postfix/relay_password 

更新Postfix查找表。

to update Postfix lookup table.

/ etc / postfix / certs 或任何您喜欢的文件夹中添加证书,然后

Add the certificates in /etc/postfix/certs, or any folder you like, then

$ sudo c_rehash /etc/postfix/certs/ 

(即,证书与Openssl)。

(i.e., rehash the certificates with Openssl).

编辑 /etc/postfix/main.cf ,以便它包括以下行(如果需要,调整路径):

Edit /etc/postfix/main.cf so that it includes the following lines (adjust the paths if needed):

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

/ li>

  • 最后,只需重新加载Postfix进程,例如

  • Finally, just reload the Postfix process, with e.g.

    $ sudo postfix reload 
    

    ($ code> start / 停止的组合)也可以。

    (a combination of start/stop works too).

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

    You can choose a different port for the SMTP, e.g. 465. It’s still possible to use SASL without TLS (the above steps are basically the same), but in both case the main problem is that your login informations are available in a plan text file... Also, should you want to use your MobileMe account, just replace the Gmail SMTP server with smtp.me.com.

    这篇关于使用sendmailR包从R发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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