- Java code
class SendMail implements ActionListener{ public void actionPerformed(ActionEvent evt){ try { Properties props=new Properties(); //获得系统属性 props.put("mail.smtp.auth", "true"); //设置身份验证为true //创建邮件会话对象,并启动身份验证 Session session=Session.getDefaultInstance(props,new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(usernameField.getText(), passwordField.getText()); } }); final Message msg=new MimeMessage(session); Address to=new InternetAddress(toField.getText()); Address from=new InternetAddress(fromField.getText()); msg.setFrom(from); msg.setRecipient(Message.RecipientType.TO, to);// msg.setSentDate(new Data()); msg.setSubject(transferChinese(subjectField.getText())); msg.setContent(message.getText(), "GBK"); //启动线程来处理 Runnable r=new Runnable(){ public void run() { try { Transport.send(msg); } catch(Exception e){ e.printStackTrace(); } } }; Thread t=new Thread(r); t.start(); message.setText(""); } catch(Exception e) { e.printStackTrace(); } } }
at javax.mail.internet.ContentType.<init>(ContentType.java:102)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1331)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2107)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2075)
at javax.mail.Transport.send(Transport.java:123)
at cusmsgmgt.Mail$SendMail$2.run(Mail.java:93) 注:指向的是Transport.send(msg);语句。
at java.lang.Thread.run(Thread.java:662)
求高手指教。
------解决方案--------------------
应该是配置文件有问题了。
javax.mail.internet.ParseException: Expected '/', got null
说明在读取配置信息的时候,你为空了,或者该项没有配置。
------解决方案--------------------
- Java code
props.put("mail.smtp.host","smtp.qq.com");//设置邮件服务器的域名或IP
------解决方案--------------------
private String host = "smtp.qq.com";
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Authenticator auth = new Email_Autherticator();
Session session = Session.getInstance(props, auth);
------解决方案--------------------
楼主给你发站内了