Outlook禁止使用R中的mailR对某些电子邮件地址进行身份验证

时间:2019-05-31 12:36:55

标签: java r email sendmailr

我正在尝试使用公司电子邮件从R中自动使用mailR发送电子邮件(它不允许我标记mailR,所以我用类似的包sendmailR对其进行了标记)。

我使用了这篇文章(Send authenticated mails via Outlook through R using mailR package)中的代码,虽然该代码适用于我的学校面试电子邮件,但不适用于我的公司:

 private void pictureBoxPage_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    pictureBoxPage.Invalidate();
                    region.X = e.X;
                    region.Y = e.Y;
                    region.Width = 0;
                    region.Height = 0;
                }
            }

            private void pictureBoxPage_MouseUp(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    GetRegion(e);
                }
            }

            private void GetRegion(MouseEventArgs e)
            {
                if (e.X < region.X)
                {
                    region.Width = region.X - e.X;
                    region.X = e.X;
                }
                else
                {
                    region.Width = e.X - region.X;
                }

                if (e.Y < region.Y)
                {
                    region.Height = region.Y - e.Y;
                    region.Y = e.Y;
                }
                else
                {
                    region.Height = e.Y - region.Y;
                }

                pictureBoxPage.Invalidate();
            }

            private void pictureBoxPage_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawRectangle(new Pen(Color.Red, 5), region);
            }

            private void pictureBoxPage_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    GetRegion(e);
                    pictureBoxPage.Invalidate();
                }
            }

我100%确保我使用了正确的用户名,密码等,但是仅在使用公司电子邮件时会收到此错误消息:

send.mail(from = "me@companydomain.com",
to = c("coworker@companydomain.com"),
subject = "Test Email",
body = "Hi Coworker! Did this email send?",
authenticate = TRUE,
smtp = list(host.name = "smtp.office365.com",
port = 587,
user.name = "me@companydomain.com",
passwd = "Password1",
sls = TRUE,
tls = TRUE),
debug = TRUE)

最后,因为我收到此错误,所以我打开了调试,这是它的报告。据我所知,我的电子邮件是第一次通过身份验证并连接到服务器,但是最后,它再次失败了。据我所知,除非引擎盖下发生任何事情,否则我们没有两因素身份验证。

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.office365.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [MN2PR05CA0017.namprd05.prod.outlook.com]

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:892)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:814)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
    at javax.mail.Service.connect(Service.java:386)
    at javax.mail.Service.connect(Service.java:245)
    at javax.mail.Service.connect(Service.java:194)
    at javax.mail.Transport.send0(Transport.java:253)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 6 more
NULL
Error: EmailException (Java): Sending the email to the following server failed : smtp.office365.com:587

我希望能够在保持安全性的同时发送这些自动电子邮件。这有可能吗?我知道错误提到Java中的内容,我不知道,所以也许这是关键吗?谢谢!

1 个答案:

答案 0 :(得分:0)

尝试一下:

send.mail(from = "me@companydomain.com",
to = c("coworker@companydomain.com"),
subject = "Test Email",
body = "Hi Coworker! Did this email send?",
smtp = list(host.name = "companydomain.mail.protection.outlook.com", port = 25, user.name   = "me@companydomain.com", passwd = "Password1"),
authenticate = TRUE,
debug = TRUE)

请注意,我已将SMTP主机名从smtp.office365.com更改为companydomain.mail.protection.outlook.com,并设置了port = 25

我从Microsoft的Office 365文档页面中学到了这一点。