呃……貌似快两个月前的帖子了…… 应该问题解决了吧……不过看了下,貌似回帖里面没有正确答案…… 补上好了……Expected '/', got null 异常,是因为 msg.setContent(message.getText(), "GBK"); 这个"GBK"引起的…… 要写成MIME那种形式——"text/html;charset=GBK"PS:不知道这个message是神马,不过看起来getText()方法像返回了个字符串…… 话说,这里不包装成MimeMultipart神马的真的没问题么?最后,附上段APIsetContentpublic void setContent(Object o, String type) throws MessagingException A convenience method for setting this Message's content. The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do setContent(foobar, "application/x-foobar"), a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.Specified by: setContent in interface Part Parameters: o - the content object type - Mime type of the object Throws: IllegalWriteException - if the underlying implementation does not support modification of existing values IllegalStateException - if this message is obtained from a READ_ONLY folder. MessagingException
这个message是个什么东东,自己打印一下试试
javax.mail.internet.ParseException: Expected '/', got null
说明在读取配置信息的时候,你为空了,或者该项没有配置。
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Authenticator auth = new Email_Autherticator();
Session session = Session.getInstance(props, auth);
应该问题解决了吧……不过看了下,貌似回帖里面没有正确答案……
补上好了……Expected '/', got null
异常,是因为
msg.setContent(message.getText(), "GBK");
这个"GBK"引起的……
要写成MIME那种形式——"text/html;charset=GBK"PS:不知道这个message是神马,不过看起来getText()方法像返回了个字符串……
话说,这里不包装成MimeMultipart神马的真的没问题么?最后,附上段APIsetContentpublic void setContent(Object o,
String type)
throws MessagingException
A convenience method for setting this Message's content.
The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do setContent(foobar, "application/x-foobar"), a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.Specified by:
setContent in interface Part
Parameters:
o - the content object
type - Mime type of the object
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
message.setSubject("---订单支付成功邮件-----");
message.setContent("订单号*************已经支付成功","text/html;charset=utf-8");