Java tutorial
/* * Copyright 2011 MOPAS(Ministry of Public Administration and Security). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package egovframework.rte.tex.com.service.impl; import egovframework.rte.fdl.cmmn.EgovAbstractServiceImpl; import egovframework.rte.tex.com.service.EgovMailService; import egovframework.rte.tex.mbr.service.MemberVO; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; /** * ?? ? ?. * * @author * @since 2011.06.07 * @version 1.0 * @see <pre> * == ?(Modification Information) == * * ? ? * ------- -------- --------------------------- * 2011.06.07 ? * * </pre> */ @Service("mailService") public class EgovMailServiceImpl extends EgovAbstractServiceImpl implements EgovMailService { //SpEL? properties ? //@Resource(name="mailInfoService") //protected EgovPropertyService mailInfoService ; //SpEL? START /** HOST NAME */ @Value("#{mailInfoService.hostName}") private String hostName; /** PORT */ @Value("#{mailInfoService.port}") private int port; /** MAIL ID */ @Value("#{mailInfoService.mailId}") private String mailId; /** MAIL PASSWORD */ @Value("#{mailInfoService.mailPass}") private String mailPass; /** MAIL NAME */ @Value("#{mailInfoService.mailName}") private String mailName; /** MAIL SUBJECT*/ @Value("#{mailInfoService.subject}") private String subject; //SpEL? END /** * ? ?? ?? . * @param vo ? * @return ? */ @Override @SuppressWarnings("deprecation") public boolean sendEmailTo(MemberVO vo) { boolean result = false; Email email = new SimpleEmail(); email.setCharset("utf-8"); // ? // setHostName? ? // email.setHostName(mailInfoService.getString("hostName")); // SpEL? properties ? email.setHostName(hostName); // SMTP email.setSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(mailId, mailPass)); email.setTLS(true); try { email.addTo(vo.getEmail(), vo.getId()); // ? } catch (EmailException e) { e.printStackTrace(); } try { email.setFrom(mailId, mailName); // } catch (EmailException e) { e.printStackTrace(); } email.setSubject(subject); // ? email.setContent("ID: " + vo.getId() + "<br>" + "PASSWORD: " + vo.getPassword(), "text/plain; charset=utf-8"); try { email.send(); result = true; } catch (EmailException e) { e.printStackTrace(); } return result; } }