boolean sessionDebug = false;
InternetAddress[] address;
//設定所要用的Mail伺服器和所使用的傳輸協定
java.util.Properties props = System.getProperties();
props.put("mail.host","202.203.201.11");
props.put("mail.transport.protocol","smtp");
//產生新的maill session
javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
MimeMessage msg = new MimeMessage(mailSession);
//設定傳送郵件的發信人
msg.setFrom(new InternetAddress("ccccxxx@gmail.com","USERNAME"));
//設定收信人的信箱
address = InternetAddress.parse(sendmail,false);
msg.setRecipients(Message.RecipientType.TO, address);
//設定郵件主題
msg.setSubject(sub,"BIG5");
//設定發信時間
msg.setSentDate(new java.util.Date());
//設定郵件內容
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
//設定傳送信的MIME Type
mbp.setContent(message,"text/html;charset=Big5");
mp.addBodyPart(mbp);
msg.setContent(mp);
//傳送郵件
Transport.send(msg);
沒有留言:
張貼留言