在Mac上使用mailR使用gmail SMTP发送邮件的问题

时间:2017-10-08 02:55:53

标签: r macos email gmail

我在收到R邮件脚本发送邮件时遇到问题。我尝试了不支持身份验证的sendmailR,但无法使其工作并花时间尝试让mailR send.mail工作。这是我的代码:

 send.mail(from = "my.mail@gmail.com",
 to = "my.mail@gmail.com",
 subject = "Subject of the email",
      body = "Body of the email",
      smtp = list(host.name = "smtp.gmail.com", 
      port = 465, user.name = "my.mail@gmail.com", 
      passwd = "my.password", ssl = TRUE),
      authenticate = TRUE,
      send = TRUE)

以下是我得到的错误:

org.apache.commons.mail.EmailException: Sending the email to the following 
server failed : smtp.gmail.com:465
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:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.NULL
java:597)
at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.8 Username and 
  Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials l135sm1714011oib.8 - gsmtp

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

错误:EmailException(Java):将电子邮件发送到以下服务器失败:smtp.gmail.com:465

我正在使用Google进行双重身份验证,但我使用SMTP Google服务器设置了应用密码,并且我已经使用了所有邮件应用3年。任何建议表示赞赏。

0 个答案:

没有答案