2011-05-03 63 views
14

我試圖使用sendmailR軟件包從R發送電子郵件。下面的代碼在我的電腦上運行時工作正常,我收到了電子郵件。然而,當我跟我的MacBook Pro運行它,它失敗,出現以下錯誤:使用sendmailR軟件包從R發送電子郵件

library(sendmailR) 
from <- sprintf("<[email protected]%s>", Sys.info()[4]) 
to <- "<[email protected]>" 
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 

任何想法,爲什麼會在電腦上工作,但不是Mac?我在兩臺機器上都關閉了防火牆。

+0

你有沒有試過不同的端口,即587? – wkmor1 2011-05-03 02:28:31

+0

@ wkmor1我試圖在sendmailR控制參數中設置端口587,但它似乎仍然在25以上通信。任何想法? – Zach 2011-05-03 02:39:06

回答

26

你能通過命令行發送電子郵件嗎?

所以,首先,啓動終端,然後

$ echo 「Test 123」 | mail -s 「Test」 [email protected] 

查找到/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/postfixrelay_password,把一行像這樣(與你的正確的用戶名和密碼):

    smtp.gmail.com [email protected]:password 
    

    然後在終端,

    $ sudo postmap /etc/postfix/relay_password 
    

    更新Postfix的查找表。

  2. 添加證書中​​,或任何文件夾你喜歡,然後

    $ 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. 最後,只是重新加載後綴過程中,用例如

    $ sudo postfix reload 
    

    (的start/stop作品的組合太)。

您可以爲SMTP選擇不同的端口,例如, 465. 仍然可以使用SASL而不使用TLS(上述步驟基本相同),但在這兩種情況下主要問題在於您的登錄信息在計劃文本文件中可用。此外,如果您想使用MobileMe帳戶,只需用smtp.me.com替換Gmail SMTP服務器即可。

+3

+1感謝您提供非常詳細的說明 – 2014-02-11 05:28:11

相關問題