Java 프로그램을 사용하여 전자 메일 (gmail)을 보내는 데 다음 코드를 사용하고 있습니다. AuthenticationFailedException
이 표시됩니다. 나는 아래 오류를 언급했다. 어떻게 해결할 수 있을까요? 이 프로그램에서 발신자 사용자 이름, 암호를 사용하는 방법?Java 프로그램에서 메일 보내기
package internet;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class mail
{
public static void main(String [] args)
{
String to = "[email protected]";
String from = "[email protected]";
String host = "smtp.gmail.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
System.out.println("hi");
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
나는 다음과 같은 오류 당신은 t.connect(host, user, password)
이전 t.sendMessage(message, addresses)
을 사용하여 로그인 자격 증명을 제공해야
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:267)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at internet.mail.main(mail.java:59)
검사 결과를 smtp.jar를 보내는 의존성 등 를 사용하여 두 개의 항아리 ? sourceid = chrome & ie = UTF-8 & q = 코드 + + 전송 + 전자 메일 + (gmail) + + Java + 프로그램 사용 – naresh
사용자 이름과 암호는 어디에 설정합니까? 코드에서 그것을 보지 마라. –