SMTP Mail Send
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import java.security.Security;
public class SendMail
{
public static void main(String[] args)
{
Properties prop = new Properties();
prop.put("mail.smtp.user", "soltv");
prop.put("mail.smtp.host", "mail.soltv.kr");
prop.put("mail.smtp.port", "25");
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.debug", "true");
String UserName = "Mail 계정";
String PassWord = "Mail 계정 암호";
String type = "text/html; charset=KSC5601";
try
{
Authenticator authenticator = null;
authenticator = new SMTPAuthenticator(UserName, PassWord);
Session session = Session.getInstance(prop, authenticator);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setSubject("SMTP 서버를 이용한 JavaMail 테스트");
Address fromAddr = new InternetAddress("보내는메일주소"); // 보내는 사람의 메일주소
msg.setFrom(fromAddr);
Address toAddr = new InternetAddress("받는메일주소"); // 받는 사람의 메일주소
msg.addRecipient(Message.RecipientType.TO, toAddr);
String message = "SMTP 서버를 이용한 JavaMail 테스트"
+ "<img src=\"http://url_image.jpg/" />" ;
msg.setContent(message, type );
System.out.println("Message: " + msg.getContent());
Transport.send(msg);
System.out.println("SMTP서버를 이용한 메일보내기 성공");
}
catch (Exception mex)
{ // 메일전송시 오류가 발생한 경우
System.out.println("메일전송 오류 ");
mex.printStackTrace();
}
}
}
class SMTPAuthenticator extends Authenticator {
PasswordAuthentication passwordAuthentication;
SMTPAuthenticator(String userName, String password) {
passwordAuthentication = new PasswordAuthentication(userName, password);
}
public PasswordAuthentication getPasswordAuthentication() {
return passwordAuthentication;
}
}
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import java.security.Security;
public class SendMail
{
public static void main(String[] args)
{
Properties prop = new Properties();
prop.put("mail.smtp.user", "soltv");
prop.put("mail.smtp.host", "mail.soltv.kr");
prop.put("mail.smtp.port", "25");
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.debug", "true");
String UserName = "Mail 계정";
String PassWord = "Mail 계정 암호";
String type = "text/html; charset=KSC5601";
try
{
Authenticator authenticator = null;
authenticator = new SMTPAuthenticator(UserName, PassWord);
Session session = Session.getInstance(prop, authenticator);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setSubject("SMTP 서버를 이용한 JavaMail 테스트");
Address fromAddr = new InternetAddress("보내는메일주소"); // 보내는 사람의 메일주소
msg.setFrom(fromAddr);
Address toAddr = new InternetAddress("받는메일주소"); // 받는 사람의 메일주소
msg.addRecipient(Message.RecipientType.TO, toAddr);
String message = "SMTP 서버를 이용한 JavaMail 테스트"
+ "<img src=\"http://url_image.jpg/" />" ;
msg.setContent(message, type );
System.out.println("Message: " + msg.getContent());
Transport.send(msg);
System.out.println("SMTP서버를 이용한 메일보내기 성공");
}
catch (Exception mex)
{ // 메일전송시 오류가 발생한 경우
System.out.println("메일전송 오류 ");
mex.printStackTrace();
}
}
}
class SMTPAuthenticator extends Authenticator {
PasswordAuthentication passwordAuthentication;
SMTPAuthenticator(String userName, String password) {
passwordAuthentication = new PasswordAuthentication(userName, password);
}
public PasswordAuthentication getPasswordAuthentication() {
return passwordAuthentication;
}
}
댓글
댓글 쓰기
질문이나 의견은 요기에 남겨주세요 ^^,,