Send authenticated mails via Outlook through R using mailR package

一曲冷凌霜 提交于 2020-01-21 02:28:11

问题


How can I send mails from R via Outlook?

I was told to use the sendmailR package, but I could not figure out how to specify certain control settings (such as port, username and password). I was also redirected to this post, but it did not help.

I switched to the mailR package. I can send mails from other servers, such as smtp.gmail.com, but I do not know the Outlook server details. What are the protocol, server and port details required to send mails via Outlook using mailR?


回答1:


This took me a while to figure out. Try this:

send.mail(from = "username@custom.org",
          to = c("recipient1@custom.org", "recipient2@custom.org"),
          subject = "Title",
          body = "Hello from R.",
          authenticate = TRUE,
          smtp = list(host.name = "smtp.office365.com",
                  port = 587,
                  user.name = "username@custom.org",
                  passwd = "Pa55w0rd",
                  tls = TRUE))

It is a common misconception that the port is 25 or 447. I believe port 25 can only be used whenauthenticate = FALSE.

Many sources claim that the correct server is smtp-mail.outlook.com. Perhaps you could try this in the event that the code does not work. Moreover, do not use ssl = TRUE. It has to be tls = TRUE.

Shoutout to Rahul Premraj's answer to this archived 2014 question.



来源:https://stackoverflow.com/questions/53074411/send-authenticated-mails-via-outlook-through-r-using-mailr-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!