rpremraj / mailR

A utility to send emails from the R programming environment
http://rpremraj.github.io/mailR/
190 stars 57 forks source link

office 365 - not authenticated to send anonymous mail #70

Open hanoienglish opened 6 years ago

hanoienglish commented 6 years ago

when I include the line SSL = TRUE it changes port, how do I use STARTTLS ? Mail settings page says Server name: smtp.office365.com Port: 587 Encryption method: STARTTLS No settings on this account to use secondary passwords for each device or email client.

library(mailR)
send.mail(from    = "john@school.edu",
          to      = c("tom@gmail.com", "mary@yandex.ru"),
          subject = "Test R email",
          body    = "hello world",
       smtp = list(host.name = "smtp.office365.com",
                   port      = 587,
                   user.name = "john@school.edu",
                   passwd    = "redacted",
                authenticate = TRUE),
                   send      = 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(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at RJavaTools.invokeMethod(RJavaTools.java:386) Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [SG2PR06CA0108.apcprd06.prod.outlook.com]

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2202)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1693)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)
at javax.mail.Transport.send0(Transport.java:254)
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

humbertcostas commented 5 years ago

Same problem here, did you found a solution?

ashishzankar commented 5 years ago

Type this command : dig MX yourdomain.com In the output search for ANSWER SECTION. you should find a FQDN of yourdomain.com Use that instead of smtp.office365.com

example : dig MX mydoamin.com admin@lincoln:~/>: dig MX mydomain.com

; <<>> DiG 9.9.6-P1 <<>> MX mydomain.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16984 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1280 ;; QUESTION SECTION: ;mydomain.com. IN MX

;; ANSWER SECTION: mydomain.com. 600 IN MX 0 mydomain.com.mail.protection.outlook.com. mydomain.com. 600 IN MX 10 mydomain.com.mail.protection.outlook.com. mydomain.com. 600 IN MX 15 mydomain.com.mail.protection.outlook.com.

;; AUTHORITY SECTION: mydomain.com. 3600 IN NS xyz.domaincontrol.com. mydomain.com. 3600 IN NS abc.domaincontrol.com.

;; Query time: 89 msec ;; SERVER: 10.6.254.4#53(10.6.254.4) ;; WHEN: Thu Feb 28 03:42:00 PST 2019 ;; MSG SIZE rcvd: 171 ================end of output of dig command =================

mydomain.com. 600 IN MX 0 mydomain.com.mail.protection.outlook.com. mydomain.com. 600 IN MX 10 mydomain.com.mail.protection.outlook.com. mydomain.com. 600 IN MX 15 mydomain.com.mail.protection.outlook.com.

use any of the above. The numbers 0, 10 and 15 etc is like the priority. Do not worry about it. Instead of smtp.office365.com, use mydomain.com.mail.protection.outlook.com or any of the remaining two. It should work.

ashishzankar commented 5 years ago

mydomain.com.mail.protection.outlook.com for some it may be google.com instead of outlook.com or any other. It depends on where your mailbox is registered. Let me know. Let me know, I am interested to know the result.