1
웹 응용 프로그램의 경우 전자 메일 알림을 보내는 방법을 만들었습니다. 이 메시지는 특정 계정에서 가져와야하지만, "보낸 사람"헤더 필드를 완전히 다른 전자 메일 주소로 읽으 려합니다. 여기에 (내가 가짜로 실제 이메일 주소를 변경 한) 내 코드입니다 : 내가 원하는Java MimeMessage의 "보낸 사람"헤더 필드를 올바르게 설정하지 않음
from: FAKE NAME <[email protected]>
: 다음 이메일 헤더를해야합니다 그것으로 이메일을 보내 위의 방법에 대한
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("[email protected]", "PASSWORD");
}
});
try{
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress("[email protected]", "FAKE NAME"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
message.setReplyTo(new Address[]{new InternetAddress("no[email protected]")});
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 <[email protected]>
내가 뭘 잘못하고 있니? 어떤 도움을 주셔서 감사합니다!