sendmail 에러
작성자 정보
- 박민욱 작성
- 작성일
컨텐츠 정보
- 1,775 조회
- 0 추천
- 목록
본문
sendmail을 이용 신청서를 접수하려 하는데 에러가 발생합니다.
혹 아시는분 도와 주세요. 감사합니다.
public class SendMail extends HttpServlet {
String host= "localhost";//11,16,51,52,59
String sender= "";// 보내는 사람 주소
String receiver= "";//받는 사람 주소
String topic= "";//제목
String content= "";// 내용
String mime= "";// 문서 타입
public SendMail(){
}
public SendMail(String sender2, String receiver2, String topic2, String content2, String mime2) throws IOException{
sender= sender2;
receiver= receiver2;
topic= topic2;
content= toKR(content2);
mime= mime2;
}
public boolean send() throws IOException{
Properties props = new Properties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
String receiver_tmp= "";
StringTokenizer stk= new StringTokenizer(receiver, "/");
int stkCnt= stk.countTokens();
InternetAddress[] address = new InternetAddress[stkCnt];
int i4= 0;
while(stk.hasMoreTokens()) {
receiver_tmp= stk.nextToken();
address[i4] = new InternetAddress(receiver_tmp);
i4++;
}
msg.setRecipients(Message.RecipientType.TO, address);
msg.setFrom(new InternetAddress(sender));
msg.setSubject(topic);
msg.setSentDate(new Date());
if(mime.equals("text")) msg.setText(content); // TEXT형식
else msg.setContent(content,"text/html; charset=euc-kr"); // HTML형식
Transport.send(msg);
return true;
}
catch (MessagingException e){
e.printStackTrace();
return false;
}
}
public static String toKR(String str1) throws UnsupportedEncodingException{
if(str1 == null){
return("");
}
return(new String(str1.getBytes("8859_1"), "KSC5601"));
}
}
관련자료
-
이전
-
다음