- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想使用 eclipse 从我的 gmail 帐户发送一封电子邮件到另一个邮件帐户。我使用 apache tomcat 7.0.34 作为我的网络服务器并使用端口 8080 作为 apache 服务器(HTTP/1.1)并使用 JRE 7 作为系统库,并在 Java 资源下的库中包含 mail.jar 和 activation.jar。
在下面给出了我的jsp页面,其中输入收件人地址并提交给服务器。
发送邮件.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="ControllerMail">
Recipient Address : <input type="email" name="to" ><br/><br/>
<input type="submit" value="Submit"/>
<input type="hidden" name="pageType" value="sendmail"/>
</form>
</body>
</html>
现在,我的 servlet 类如下。
ControllerMail.java
package com.sendmail.controller;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ControllerMail extends HttpServlet {
private static final long serialVersionUID = 1L;
public ControllerMail() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doProcess(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doProcess(request,response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String pageType = request.getParameter("pageType");
if(pageType.equals("SendMail"))
{
String to = request.getParameter("to");
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("********@gmail.com","********");//change accordingly
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("********@gmail.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Greetings");
message.setContent("Hi,what's up","text/html");
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
}
}
但是当我在服务器上运行我的项目时,这意味着当我右键单击我的 SendMail.jsp 页面并单击“在服务器上运行”时,会发生以下错误。
Mar 17, 2015 7:41:38 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Program Files\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_75\bin;F:\Software\JavaMailAPI\activation-jaf1.1.1.jar;F:\Software\JavaMailAPI\java-mail-1.4.4.jar;F:\Software\eclipse-jee-luna-SR1a-win32\eclipse;;.
Mar 17, 2015 7:41:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SendEmail' did not find a matching property.
Mar 17, 2015 7:41:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8081"]
Mar 17, 2015 7:41:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 539 ms
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.34
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SendEmail]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SendEmail]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:87)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 20 more
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start:
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 249 ms
45 秒后,会出现一个对话框,显示“Starting Tomcatv7.0 Server at localhost” encountered a problem。
最佳答案
java.lang.NoClassDefFoundError: javax/mail/MessagingException
添加mail.jar例如,在您的 tomcat 库 (/catalina_home/commons/libs/) 或您的 Web 应用程序文件中(参见 web-inf/lib)。
您可能还需要 activation jar .
有关最新的 javax.mail.jar,请参阅 https://java.net/projects/javamail/pages/Home
关于java.lang.ClassNotFoundException : javax. 邮件.MessagingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29101542/
我正在尝试使用 usig javax.mail 编写一个简单的邮件发送器 邮件服务: @Service public class MailServiceImpl implements MailServ
我的代码故意抛出 SourceAssertionError。在早前的 5.1.6.release 中,对于任何错误,在 RequestHandlerRetryAdvice 中,对于任何错误,它都会将其
这个问题在这里已经有了答案: getting errors even after importing jars for sending email (1 个回答) 关闭 7 年前。 package
我正在尝试编写一个简单的邮件发件人类,该类将接收一堆参数并使用这些参数将使用我们的 Exchange 2010 服务器发送电子邮件。虽然身份验证等似乎工作正常,但当代码实际尝试发送电子邮件时(我认为)
我有一个电子邮件服务,它从收件箱中提取消息,并且正在使用 try/catch 来处理 MessagingExceptions。我正在调用folder.getMessages(int start, in
嗨,我正在使用 apache Tika,我根据我的要求对 Tika 做了一些更改,并且我能够成功构建 Tika。但是当我尝试运行 Tika 时,出现以下异常,我添加了 mail.jar 和激活。 ja
我面临以下异常: javax.mail.MessagingException: 220 cnsmail.company.local Microsoft ESMTP MAIL Service ready
下面的代码是网络应用程序的一部分。它负责连接outlook邮件服务器。 ls_user_pass = ldch_sys_users.getItemValue(1, "user_password
我正在使用 eclipse indigo 运行我的 tomcat 服务器,当我启动 tomcat 服务器时,tomcat 服务器成功启动并运行,但控制台中显示错误。 ERROR - ContextL
我正在使用 javax.mail .jar 文件来阅读邮件消息。但是当我运行代码时,出现以下异常。 我在类路径中添加了 mail.jar。 Exception in thread "main" jav
在我的 Axis 1.4 Web 服务上,当传入消息损坏时会引发此异常。 WARN ;2010-07-15 14:45:38,232;org.apache.axis.attachments.Attac
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: javax.mail.MessagingException: Could not connect to SM
我有另一个convert socket 异常。 Stackoverflow 将我链接到相关答案,我已经完成了人们在那里建议的一切。 这里我们有异常描述: Exception in thread "ma
以下是我发送邮件的代码: import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message
您好,在尝试使用 spring boot 发送 SMTP 电子邮件时,按照教程进行操作后,我一直收到此错误。 失败的消息:javax.mail.MessagingException:无法确定本地电子邮
我想使用 eclipse 从我的 gmail 帐户发送一封电子邮件到另一个邮件帐户。我使用 apache tomcat 7.0.34 作为我的网络服务器并使用端口 8080 作为 apache 服务器
我使用以下代码发送邮件。短信发送工作正常,但带附件的邮件不工作,它给出了异常。如何解决这个问题 javax.mail.MessagingException: IOException while sen
我们在流量高峰期间将事件发送到 EventHub 时遇到了很多此类异常: “无法将事件发送到 EventHub。异常:Microsoft.ServiceBus.Messaging.MessagingE
我正在尝试在 CentOS 7 开发计算机上安装 JavaMail,仅使用 localhost 来发送电子邮件。为此,我安装了 dovecot、postfix 和 mailx。我刚刚使用 the in
当我尝试从 Java 邮件 API 发送邮件时遇到以下异常: javax.mail.MessagingException: Can't send command to SMTP host; neste
我是一名优秀的程序员,十分优秀!