3

I want to use {mailR} package to send email notifications with authentication. This package is backended by {rJava} and uses Java facilities.

I registered an Outlook.com account.

Here's the code:

library(mailR)
email <- send.mail(
  from="(account-name)@outlook.com",
  to="(my-account)@outlook.com",
  subject="Test message from server",
  body="Hello, this is a test message.",
  smtp=list(host.name="smtp-mail.outlook.com",port=25,
    user.name="(account-name)@outlook.com",passwd="(account-password)", 
    ssl = TRUE),
  authenticate=TRUE,
  send=TRUE
)

I read http://windows.microsoft.com/en-us/windows/outlook/send-receive-from-app and tried all possible host names (smtp.live.com, smtp.outlook.com, smtp-mail.outlook.com) and ports (25, 587), but it all results in the following error:

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp-mail.outlook.com:465

What is the problem? Is there a working solution to send email with authentication in R?

Kun Ren
  • 4,715
  • 3
  • 35
  • 50

1 Answers1

1

Try the code below (been tested by other Outlook users):

send.mail(from = from,
          to = to,
          subject = subject,
          body = msg, 
          authenticate = TRUE,
          smtp = list(host.name = "smtp.office365.com", port = 587,
                      user.name = "xxx@domain.com", passwd = "xxx", tls = TRUE))
Rahul Premraj
  • 1,595
  • 14
  • 13