일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 안드로이드
- java
- sha1 convert hashkey
- FlexiblePageView
- Push
- Objective C
- android log dump
- apns
- Status Bar
- appbarlayout
- ios framework
- ios
- JavaScript Engine
- PageControl
- Google V8 Engine
- apache
- IOS10
- V8 Engine
- Magnify Anim
- 공인인증서 정보
- 인증서 정보 뽑아내기
- Android
- embedd
- v8 engine xcode build
- SO 파일
- apk 다운사이징
- Android NDK시스템
- so file
- IMAGE
- 공인인증서 만료일
- Today
- Total
caTea 블로그
java mail sand example 본문
<!-- Mail maven setting-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
import java.util.Date;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.mail.internet.MimeMultipart;
import org.apache.log4j.Logger;
public class MailSendManger {
private Logger log = Logger.getLogger(MailSendManger.class);
private final String sendId = "";
private final String sendPwd = "";
public String send(String toMailAddr, String title, String content){
Properties prop = new Properties();
//-- gmail account 이용
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.transport.protocol", "smtp");
prop.setProperty("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
prop.put("mail.smtp.port", "465");
prop.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(sendId, sendPwd);
}
});
session.setDebug(true); //for debug
try{
MimeMessage message = new MimeMessage(session);
message.setSubject(title,"UTF-8");
message.setSentDate(new Date());
message.setRecipient(RecipientType.TO, new InternetAddress(toMailAddr)); //RecipientType.TO:수신자 RecipientType.CC:참조자
// This HTML mail have to 2 part, the BODY and the embedded image
MimeMultipart multipart = new MimeMultipart("related");
// first part (the html)
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(content, "text/html;charset=utf-8");
// add it
multipart.addBodyPart(messageBodyPart);
// second part (the image)
// messageBodyPart = new MimeBodyPart();
//DataSource fds = new FileDataSource(imgFile);
//messageBodyPart.setDataHandler(new DataHandler(fds));
//messageBodyPart.setHeader("Content-ID","imgFile");
// add it
//multipart.addBodyPart(messageBodyPart);
// put everything together
message.setContent(multipart);
Transport.send(message);
} catch (Exception e){
e.printStackTrace();
log.debug("============ Fail Send Mail ============");
return "false";
}
log.debug("============ Succes Send Mail ============");
return "succes";
}
}
'spring(java)' 카테고리의 다른 글
html convert pdf (html문서를 pdf 파일로 변환) (0) | 2016.05.11 |
---|---|
http 데이터 송수신 클라이언트단 (0) | 2016.01.29 |
java excel paser example (0) | 2015.09.10 |
apache ftpclient example (0) | 2015.09.10 |
Method 함수 사용해보자 (0) | 2015.06.17 |