다음 코드는 javamail API를 사용하여 Java 응용 프로그램에서 전자 메일 (gmail 사용)을 보내는 데 사용됩니다.요청한 대상에 대한 유효한 인증 경로를 찾을 수 없음 (avast가 설치된 Windows에서)
Linux (Kubuntu 16.04)에서는 제대로 작동하지만 Windows에서는 Avast 바이러스 백신 쉴드가 켜져 있습니다. 나는 모든 똑바로 방패를 사용하지 않으면
public void doSendGmail(){
Connection con = Functions.ConnectToDB();
try {
Statement stmt = con.createStatement();
String sqlQuery = "select * from settings";
ResultSet rs = stmt.executeQuery(sqlQuery);
while(rs.next()){
String email = rs.getString("Email");
//String pass = rs.getString("Password");
byte [] pass = rs.getBytes("Password");
cipher = Cipher.getInstance("DES/CTR/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec,ivspec);
byte [] plain_text = cipher.doFinal(pass);
from = email;
password = new String(plain_text);
}
con.close();// close the connection
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error retrieving email address and password\n"+e.toString(),
"Error",JOptionPane.ERROR_MESSAGE);
}
to = txtTo.getText();
cc = txtCC.getText();
bcc = txtBCC.getText();
subject = txtSubject.getText();
message_body = jtaMessage.getText();
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
/*use authenticator as username and password are supplied 'on demand' i.e queried from database
or supplied via a login dialog*/
Session session = Session.getInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(from, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
if(!cc.equals("")){
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
}
if(!bcc.equals("")){
message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc));
}
message.setSubject(subject);
if(filePathList.isEmpty()){// if a file(s) have not been attached...
message.setText(message_body);
Transport.send(message);
}
else{// if a file(s) have been attached
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(message_body);// actual message
Multipart multipart = new MimeMultipart();// create multipart message
multipart.addBodyPart(textPart);//add the text message to the multipart
for(int i =0; i<filePathList.size(); i++){// use for loop to attach file(s)
MimeBodyPart attachmentPart = new MimeBodyPart();
DataSource source = new FileDataSource((String)filePathList.get(i));
attachmentPart.setDataHandler(new DataHandler(source));
attachmentPart.setFileName((String)fileList.get(i));
multipart.addBodyPart(attachmentPart);// add the attachment to the multipart
message.setContent(multipart);// add the multipart to the message
}
Transport.send(message);
}
JOptionPane.showMessageDialog(this, "Message Sent!","Sent",JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error sending email message\n"+e.toString(),
"Error",JOptionPane.ERROR_MESSAGE);
}
}
는 다음과 같은 오류 메시지가
를 표시, 그냥 완벽 메일 메시지를 보냅니다.어떻게 문제를 해결할 수 있습니까?
다른 바이러스 백신도 동일한 효과를 줍니까?
mail.smtp.ssl.trust 속성을 true 및 false로 설정했지만 여전히 작동하지 않았습니다. 즉, props.put ("mail.smtp.ssl.trust", "true"); – David
(위에 링크 된) 부동산 설명을 읽었습니까? "true"로 설정하면 "true"라는 호스트를 트러스트합니다. 모든 호스트를 신뢰하려면 "*"로 설정하십시오. –
그래, 나도 그랬어. 그것은 작동하지 않았다. InstallCert 프로그램을 사용해보고 작동하는지 확인해 보겠습니다. – David