2

R で sendemailR パッケージを使用しようとしていますが、修正方法がわからないエラーが発生します。

デフォルトのパラメーターを試す場合:

library(sendmailR)
from <- "your_email"
to <- "your_email"
subject <- "Test send email in R"
body <- "It works!"                     
mailControl=list(smtpServer="smtp.gmail.com")
sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)

エラーが発生します

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) :
Gmail SMTP Server:25 cannot be opened

ポートを 465 に変更すると、うまくいくようです

library(sendmailR)
from <- "your_email"
to <- "your_email"
subject <- "Test send email in R"
body <- "It works!"                     
mailControl=list(smtpServer="smtp.gmail.com", smtpPort="465")
sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)

しかし、その後、次のエラーが表示されます

Error in if (code == lcode) { : argument is of length zero

何が起こっているのか分かりますか?

これは R と Windows のバージョンです

R version 3.0.3 (2014-03-06) -- "Warm Puppy"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

ありがとう!

4

1 に答える 1

4

あなたの例では、注意が必要なことが 2 つあります。

@David Arenburgがコメントしたようにto、有効な電子メール アドレスを含める必要があります。

2 つ目は、使用している smtp サーバーですsmtp.gmail.com。このサーバーには、sendmailR でサポートされていない認証が必要です。

認証を必要としない smtp サーバーを使用できます (例: 制限付き gmail smtp サーバー: aspmx.l.google.com、ポート 25、詳細についてはこちらを参照) 。

もう 1 つのオプションは、mailR認証を許可するパッケージを使用することです。

次のようなことを試してください (もちろん、有効なメールアドレスと user.name と passwd を機能させる必要があります):

library(mailR)
sender <- "SENDER@gmail.com"
recipients <- c("RECIPIENT@gmail.com")
send.mail(from = sender,
to = recipients,
subject="Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465, 
        user.name="YOURUSERNAME@gmail.com", passwd="YOURPASSWORD", ssl=TRUE),
authenticate = TRUE,
send = TRUE)

それが役に立てば幸い、

アレックス

于 2014-05-21T21:37:08.493 に答える