테스트를 통해 이메일을 보내려고하면이 클래스를 주 클래스로 호출합니다.Java 생성자가 정의되지 않았습니다.
public class SendMail{
public SendMail(String fromMail,String tomail, Exception e)
{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]","testpw");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromMail));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(tomail));
message.setSubject("xxxxx");
message.setText("xxxxx"+ ExceptionUtils.getStackTrace(e));
Transport.send(message);
System.out.println("Done");
}
catch (MessagingException ex) {
throw new RuntimeException(ex);
}
}
public SendMail(String string, String line) {
그래서 나는이 목록에있는 모든 이메일을 보내드립니다 있도록 txt 파일에서 이메일 목록을 당길 수 있도록, 내 다른 클래스에서이 전화를합니다. 그 코드는 다음과 같습니다
String fileName = "/xxx/xxx/xxx/text.txt";
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = br.readLine()) !=null) {
new SendMail("[email protected]", line);
}
}
catch (IOException e) {
e.printStackTrace();
}
문제는이 생성자 센드 (문자열, 문자열) 정의되지 않은 나에게 말하고 있다는 것입니다.
내 고유 코드가 작동하지만 하드 코딩 된 이메일 만 보낼 수 있습니다.
try{
}
catch(Exception e)
{
e.printStackTrace();
new SendMail("senderemail","reciveremail",e); }
}
왜 내 생성자를 허용하지 않습니까?
편집 : 제작자가 잘못되지 않았습니다. 나는 ~였다! 나는 그것이 작동하지 않을 것이고 나의 문제를 해결할 이유를 발견했다. 이것은 내가 지금 사용하고있는 코드입니다.
String fileName = "/Users/cdolan/Desktop/liness.txt";
String Email = "";
try(BufferedReader br = new BufferedReader(new FileReader(fileName))) {
while ((Email = br.readLine()) !=null)
{
<Test code here goes here>
}
}
catch(Exception e)
{
e.printStackTrace();
new SendMail("[email protected]",Email,e); }
}
"문제는 SendMail (String, String) 생성자가 정의되지 않았 음을 알려주는 것입니다." 이는 아마도 SendMail (String, String) 생성자를 정의하지 않았기 때문일 것입니다. – resueman