我正致力于通过JavaMail API发送邮件。 源代码
Properties props = new Properties();
Session mailSession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(Sender));
String[] toAddresses = null;
toAddresses = addToRecepients(f_StrtoAdd, msg, toAddresses);
String[] ccAddresses = null;
ccAddresses = addCCRecepients(f_StrccAdd, msg, ccAddresses);
String[] bccAddresses = null;
bccAddresses = addBccRecepients(f_StrbccAdd, msg,
bccAddresses);
Multipart mp = formMsgContents();
msg.setSentDate(new Date());
m_log.warning(""+msg.getSentDate());
msg.setContent(mp);
msg.saveChanges();
我在msg.saveChanges()上遇到异常; - 异常消息缺少“;”。
StackTrace-
ErrorHandler errorHandler: Exception message : Missing ';'
ErrorHandler errorHandler: Error in class TestServlet
ErrorHandler errorHandler:
javax.mail.internet.ParameterList.<init>(ParameterList.java:135)
ErrorHandler errorHandler:
javax.mail.internet.ContentType.<init>(ContentType.java:72)
ErrorHandler errorHandler:
javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:530)
ErrorHandler errorHandler:
javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:133)
ErrorHandler errorHandler:
javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1393)
ErrorHandler errorHandler:
javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1366)
ErrorHandler errorHandler:
TestServlet.service(TestServlet.java:200)
ErrorHandler errorHandler:
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
ErrorHandler errorHandler:
org.owasp.csrfguard.CsrfGuardFilter.doFilter(CsrfGuardFilter.java:59)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
ErrorHandlerFilter.doFilter(ErrorHandlerFilter.java:26)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
ClickjackFilter.doFilter(ClickjackFilter.java:26)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
XSSFilter.doFilter(XSSFilter.java:55)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
ErrorHandler errorHandler:
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
ErrorHandler errorHandler:
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
ErrorHandler errorHandler:
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
ErrorHandler errorHandler:
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
ErrorHandler errorHandler:
com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)
ErrorHandler errorHandler:
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
ErrorHandler errorHandler:
org.mortbay.jetty.Server.handle(Server.java:326)
ErrorHandler errorHandler:
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
ErrorHandler errorHandler:
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
ErrorHandler errorHandler:
com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
ErrorHandler errorHandler:
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
ErrorHandler errorHandler:
com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
ErrorHandler errorHandler:
com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:480)
ErrorHandler errorHandler:
com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
ErrorHandler errorHandler:
com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
ErrorHandler errorHandler:
com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
ErrorHandler errorHandler:
com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
ErrorHandler errorHandler:
com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
ErrorHandler errorHandler:
com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
ErrorHandler errorHandler:
com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
ErrorHandler errorHandler:
java.lang.Thread.run(Thread.java:724)
请帮助我。
答案 0 :(得分:1)
您收到的内容类型无效,因为在传输时会将空白空间添加到相应的字符串中,因此请登录到控制台并重试。