[問題] jsp的寄信功能
因為想利用jsp網頁+smtp的功能來實作
但因為smtp server有限制port,所以想請問一下以下程式碼該如何改才好
ex. smtp:mail.cycu.edu.tw
port:995
//===================================================
InternetAddress[] address = null;
request.setCharacterEncoding("MS950");
String mailserver = "mail.cycu.edu.tw";
String From = request.getParameter("From");
String to = request.getParameter("To");
String Subject = request.getParameter("Subject");
String messageText = request.getParameter("Message");
boolean sessionDebug = false;
try {
// 設定所要用的Mail 伺服器和所使用的傳送協定
java.util.Properties props = System.getProperties();
props.put("mail.host",mailserver);
props.put("mail.transport.protocol","smtp");
// 產生新的Session 服務
javax.mail.Session mailSession =
javax.mail.Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
// 設定傳送郵件的發信人
msg.setFrom(new InternetAddress(From));
// 設定傳送郵件至收信人的信箱
address = InternetAddress.parse(to,false);
msg.setRecipients(Message.RecipientType.TO, address);
// 設定信中的主題
msg.setSubject(Subject);
// 設定送信的時間
msg.setSentDate(new Date());
// 設定傳送信的MIME Type
msg.setText(messageText);
// 送信
Transport.send(msg);
out.println("郵件己順利傳送");
}
catch (MessagingException mex) {
mex.printStackTrace();
}
//===================================================================
在此先謝謝各位大大幫忙了!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.43.225.248
→
09/07 09:23, , 1F
09/07 09:23, 1F
→
09/08 15:50, , 2F
09/08 15:50, 2F
→
09/08 15:50, , 3F
09/08 15:50, 3F
→
09/09 12:54, , 4F
09/09 12:54, 4F
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章