当我尝试使用JavaMail API发送邮件时收到此错误.我确信用户名和密码是100%正确的.我正在连接的Gmail帐户是一个旧帐户,因为他们说它需要时间来处理新帐户.
DEBUG SMTP RCVD: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 x35sm3011668
wfh.6
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.AuthenticationFailedException
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at Main.(Main.java:41)
at Main.main(Main.java:51)
这是我的代码:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Main
{
String d_email = "abc@gmail.com",
d_password = "pass",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "abc@gmail.com",
m_subject = "Testing",
m_text = "testing email.";
public Main()
{
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host); … 我想使用JavaMailAPI发送邮件
我做了一些编码,但它没有工作抛出异常: -
消息发送Failedjavax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码.
package com.appreciationcard.service;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.appreciationcard.dao.DAOFactory;
import com.appreciationcard.forms.ComposeForm;
public class MailServiceImpl implements MailService {
public boolean mailsent(ComposeForm composeForm) {
String to = composeForm.getTo();
String from = composeForm.getFrom();
String cc = composeForm.getCc();
String bcc = composeForm.getBcc();
String subject = composeForm.getSubject();
String messages = composeForm.getMessage();
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.port", "587");
props.put("mail.transport.protocol", "smtp");
props.put("mail.debug", "true");
System.out.println("Properties" + …Run Code Online (Sandbox Code Playgroud) public class MailEx {
public static void main(String[] args) {
try {
String userName = "abc@gmail.com";
String password = "123";
String hostName = "smtp.gmail.com";
String fromName = "Splendore Bkk";
String to[] = {"xyz@gmail.com"};
System.out.println("to.length::"+to.length);
Properties props = new Properties();
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.debug", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
System.out.println("to.length:sadfsadfds:"+to.length);
// Get the default Session object.
Session session = Session.getInstance(props);
// Create a default MimeMessage object.
MimeMessage message1 = new …Run Code Online (Sandbox Code Playgroud) 发送邮件时出错。尽管 application.properties 中的确切属性在几个月前就可以工作。
这是在 application.properties 中配置邮件发送的属性
mail.enable=true
spring.mail.host=smtp.gmail.com
spring.mail.username=abc@gmail.com
spring.mail.password=**************
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.socketFactory.port=465
mail.smtp.port=2525
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
support.email=abc@gmail.com
Run Code Online (Sandbox Code Playgroud)
我该如何重新配置这个?我尝试遵循特定的密码模式。将不胜感激任何建议。
在过去的几天里,我一直在用头撞桌子,试图找出为什么在尝试实现 Java 代码以通过公司的 Outlook 服务器发送电子邮件时不断出现以下错误:
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.0 authentication failed
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
Run Code Online (Sandbox Code Playgroud)
这是有问题的代码:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendEmail3 {
public static void main(String[] args) throws Exception { …Run Code Online (Sandbox Code Playgroud)