私のテストで電子メールを送信しようとすると、このクラスを主なクラスとして呼び出します。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();
}
問題は、コンストラクタのSendMail(文字列、文字列)が定義されていない私に言っていますということです。
オリジナルのコードが動作しますが、これではハードコードされた電子メールのみを送信できます。
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