Java Mimemessage의 "From"헤더 필드 설정 올바르게 작동하지 않음
-
21-12-2019 - |
문제
웹 응용 프로그램의 경우 Im에서 일하고 있으면 이메일 알림을 보내는 방법을 작성했습니다.메시지는 특정 계정에서 가져와야하지만 "헤더 필드에서"전적으로 다른 이메일 주소로 읽을 수 있습니다.다음은 내 코드입니다 (실제 이메일 주소를 가짜로 변경하십시오) :
public static boolean sendEmail(List<String> recipients, String subject, String content){
String header = "This is an automated message:<br />"+"<br />";
String footer = "<br /><br />unsubscribe link here";
content = header + content + footer;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
//This is where the email account name and password are set and can be changed
return new PasswordAuthentication("ACTUAL.ADRESS@gmail.com", "PASSWORD");
}
});
try{
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress("FAKE.ADDRESS@gmail.com", "FAKE NAME"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
message.setReplyTo(new Address[]{new InternetAddress("no-reply@gmail.com")});
for(String recipient: recipients){
message.addRecipient(Message.RecipientType.BCC,new InternetAddress(recipient));
}
message.setSubject(subject);
message.setContent(content,"text/html");
Transport.send(message);
return true;
}catch (MessagingException mex) {
mex.printStackTrace();
return false;
}
}
.
위의 방법에 대한 이메일을 보내는 이메일은 다음 이메일 헤더가 있습니다.
from: FAKE NAME <ACTUAL.ADRESS@gmail.com>
.
읽기를 원합니다 :
from: FAKE NAME <FAKE.ADRESS@gmail.com>
.
나는 무엇을 잘못하고 있습니까?어떤 도움이 감사합니다!
해결책
당신이 할 일을 찾고있는 것은 "스푸핑"이라고합니다.Google의 SMTP 서버를 사용하는 것처럼 보입니다.이 경우이 경우이를 성공적으로 수행 할 수 없습니다.보안을 위해 Google은 "보낸 사람"주소 만 인증 된 이메일 주소로 만 허용합니다.
제휴하지 않습니다 StackOverflow