如何解决java中的com.sun.mail.smtp.SMTPSendFailedException?

我正在创建一个应用程序,我将向用户发送邮件。

但问题是当我使用Transport.send(msg)方法时,它显示以下错误:

com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required. 

我使用以下属性发送邮件。

  props.put("mail.transport.protocol", "smtp"); props.put("mail.host", smtpHostName); props.put("mail.user", smtpUser); props.put("mail.password", smtpPass); props.put("mail.smtp.auth", smtpAuth == 1 ? true : false); props.put("mail.port", smtpPort); props.put("mail.smtp.starttls.enable", smtpTLS == 1 ? true : false); 

请帮我解决这个问题。

试试这个

 props.put("mail.smtp.host", host); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "false"); props.put("mail.smtp.port", port); 

在创建会话时使用此身份validation代码

 l_session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); l_session.setDebug(true); 

我们的环境在WebSphere 7下运行。要支持安全的smtps,正确的变量以启用SMTPS AUTHorization是:

“mail.smtp s .auth = true”

实际上,根据反编译的来源,在授权邮件会话之前,WebSphere检查是否存在组成的属性:“mail。”+ transportProtocol +“。auth”设置为“true”。 这有助于我通过Gmail发送电子邮件。