private void sendMail(Hashtable gz){
String m_strContent = "<p><table><tr><td>Hello javaMail and test example!</td></tr></table></p>";
Properties provs = new Properties();
Authenticator auth = new MyAuthenticator(username,password);
provs.put("mail.smtp.host", host);
provs.put("mail.smtp.auth", "true");
provs.put("mail.transport.protocol", "smtp");
provs.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(provs,null);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
try {
message.setSubject("test javaMail");//jtfsubject.getText()
message.setSentDate(new Date());
message.setContext("Test Mail","text/html");
} catch (IOException ex) {
Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
} catch (MessagingException ex) {
Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Address toAddress = new InternetAddress(mailAddress);//yuping159@gmail.com
Address fromAddress = new InternetAddress("87523774@qq.com");
Address reply = new InternetAddress("56545465@qq.com");
message.setReplyTo(new Address[]{reply});
message.setFrom(fromAddress);
message.setRecipients(RecipientType.TO, new Address[]{toAddress});
message.saveChanges(); // implicit with send()
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(AuthenticationFailedException e){
JOptionPane.showMessageDialog(null, "密码错误");
} catch (AddressException ex) {
Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
} catch(SMTPSendFailedException e){
JOptionPane.showMessageDialog(null, "邮件发送失败");
} catch (MessagingException ex) {
Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
}
}
以上代码是使用javaMail发送邮件的,在本地测试通过,可以发送邮件,但是到2003服务器上就不行了,本人不清楚,这个smtp服务一定要开通吗,或者说和2003系统有哪些问题?2003系统没有打sp2补丁包,IIS服务中没有选择安装smtp Service这服务。
本人做的测试是,在本人的机器xp上,即使把smtp Service 服务部打钩,重新配置IIS,还是可以发送smtp邮件.
请问大侠,请提供思路,问题有可能出现在哪里?
本人QQ:87523774;
万分感谢!!!!!!!
补充说明,和代码没有什么联系,应该重smtp服务的环境考虑。