나는 (SMTP 서버를 사용하여) 전자 메일 보내기와 관련된 Spring 프레임 워크를 사용하여 Java로 은행 응용 프로그램을 구축하고 있지만 안전하지 않다고 들었습니다. 그렇다면 어떻게 Java에서 SMTP를 안전하게 할 수 있습니까? SSL 계층 및/또는 HTTPS 연결로 충분합니까? 도와주세요.Java를 사용하여 SMTP 서버를 안전하게하는 방법
감사합니다.
나는 (SMTP 서버를 사용하여) 전자 메일 보내기와 관련된 Spring 프레임 워크를 사용하여 Java로 은행 응용 프로그램을 구축하고 있지만 안전하지 않다고 들었습니다. 그렇다면 어떻게 Java에서 SMTP를 안전하게 할 수 있습니까? SSL 계층 및/또는 HTTPS 연결로 충분합니까? 도와주세요.Java를 사용하여 SMTP 서버를 안전하게하는 방법
감사합니다.
java 응용 프로그램에서 SMTP를 보안 설정하는 대신 서버가 특정 ID에서만 메일을 릴레이하고 다른 사용자는 무시하도록 SMTP 서버를 구성 변경해야합니다.
분명히 SSL을 통한 SSL을 사용할 수 있습니다.
XML 자원
package test.mail;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.test.AbstractDependencyInjecti onSpringContextTests;
/**
* MailTest.
* @author jalarcon
*/
public class MailTest extends AbstractDependencyInjectionSpringContextTests {
private MailSender mailSender;
private SimpleMailMessage mailMessage;
/* (non-Javadoc)
* @see org.springframework.test.AbstractSingleSpringConte xtTests#getConfigLocations()
*/
@Override
protected String[] getConfigLocations() {
return new String[] {"/beanDictionary/mail.xml"};
}
public void testSendMail() {
//Create a thread safe "sandbox" of the message
SimpleMailMessage msg = new SimpleMailMessage(this.mailMessage);
msg.setTo("[email protected]");
msg.setText("This is a test");
try{
mailSender.send(msg);
} catch(MailException ex) {
throw new RuntimeException(ex);
}
}
// ---------------------------------------------------------- getters/setters
/**
* @return the mailSender
*/
public MailSender getMailSender() {
return mailSender;
}
/**
* @param mailSender the mailSender to set
*/
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
/**
* @return the mailMessage
*/
public SimpleMailMessage getMailMessage() {
return mailMessage;
}
/**
* @param mailMessage the mailMessage to set
*/
public void setMailMessage(SimpleMailMessage mailMessage) {
this.mailMessage = mailMessage;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="protocol" value="smtps" />
<property name="username" value="[email protected]"/>
<property name="password" value="yourPassword"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
</props>
</property>
</bean>
<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage" >
<property name="from" value="[email protected]" />
<property name="subject" value="Your Subject" />
</bean>
</beans>
테스트 클래스 다음은 샘플입니다