通过outlook发送电子邮件

时间:2015-01-20 19:51:16

标签: java outlook

我找到了一个可以帮助我使用我的Outlook从我的java发送邮件的软件包,它被称为Java Outlook Connector。 我把代码和正常编译但是当我发送电子邮件时发生错误。 这个错误是java没有找到我导入的类。另一方面,我仔细导入了类并将它们插入到我的Jdeveloper库中,但仍然出现错误。 我认为主要是错误现在是由于没有正确设置java库路径。我该如何解决这个问题?

以下是我的代码和错误

谢谢

import com.moyosoft.connector.com.*;
import com.moyosoft.connector.exception.*;
import com.moyosoft.connector.ms.outlook.*;
import com.moyosoft.connector.ms.outlook.folder.*;
import com.moyosoft.connector.ms.outlook.item.*;
import com.moyosoft.connector.ms.outlook.mail.*;

    public void testbutton_action() {



       try
              {



         //   System.load("C:\\Program Files (x86)\\Java\\jdk1.7.0_71\\bin\\moyocore_x64.dll");

       //  Outlook.setLibraryPath("C:\\Program Files (x86)\\Java\\jdk1.7.0_71\\bin\\moyocore.dll");


                 // Outlook application
                 Outlook outlookApplication = new Outlook();

                 // Get the Outbox folder
                 OutlookFolder outbox = outlookApplication.getDefaultFolder(FolderType.OUTBOX);

                 // Create a new mail in the outbox folder
                 OutlookMail mail = (OutlookMail) outbox.createItem(ItemType.MAIL);

                 // Set the subject, destination and contents of the mail
                 mail.setSubject("Hello world !");
                 mail.setTo("me@test.com");
                 mail.setBody("This is a test message.");

                 // Send the mail
                 mail.send();

                 // Dispose the library
                 outlookApplication.dispose();
              }
              catch(ComponentObjectModelException ex)
              {
                 System.out.println("COM error has occured: ");
                 ex.printStackTrace();
              }
              catch(LibraryNotFoundException ex)
              {
                 // If this error occurs, verify the file 'moyocore.dll' is present
                 // in java.library.path
                 System.out.println("The Java Outlook Library has not been found.");
                 ex.printStackTrace();



    }
}

以下是错误 javax.faces.el.E​​valuationException://C:/Users/Darwish/AppData/Roaming/JDeveloper/system11.1.2.4.39.64.36.1/o.j2ee/drs/New/Project1WebApp.war/fields.jsf @ 9 ,70 action ="#{TheBean.testbutton_action}":java.lang.NoClassDefFoundError:com / moyosoft / connector / com / ComponentObjectModelException     at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)     at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)     在org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)     在javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)     在javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:973)     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:354)     在oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:202)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)     在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:227)     在weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)     在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)     在weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:125)     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl $ FilterListChain.doFilter(TrinidadFilterImpl.java:468)     在oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl $ FilterListChain.doFilter(TrinidadFilterImpl.java:468)     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:293)     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:199)     在org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:173)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     at oracle.security.jps.ee.http.JpsAbsFilter $ 1.run(JpsAbsFilter.java:119)     at java.security.AccessController.doPrivileged(Native Method)     at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)     在oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)     在oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)     at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)     at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     在weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)     在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)     at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)     at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3681)     在weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)     在weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)     在weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)     在weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)     在weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)     在weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)     在weblogic.work.ExecuteThread.run(ExecuteThread.java:178) 引起:java.lang.NoClassDefFoundError:com / moyosoft / connector / com / ComponentObjectModelException     在project1.TheBeanC.testbutton_action(TheBeanC.java:67)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)     at com.sun.el.parser.AstValue.invoke(Unknown Source)     at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)     at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)     at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)     ......还有44个 引起:java.lang.ClassNotFoundException:com.moyosoft.connector.com.ComponentObjectModelException     在weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)     在weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)     在weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)     at java.lang.ClassLoader.loadClass(ClassLoader.java:305)     at java.lang.ClassLoader.loadClass(ClassLoader.java:246)     在weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)     在weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)     ... 53更多

3 个答案:

答案 0 :(得分:0)

即使您只有Intranet,也可以使用“普通”方法发送电子邮件。除了电子邮件系统的用户友好界面之外,Outlook不是什么特别的东西。确切地说,只要您可以连接到邮件服务器,即使它是Intranet,您也可以使用smtp protocal发送电子邮件。

答案 1 :(得分:0)

Outlook是一个COM服务器,您可以使用OLE COM技术自动执行。我不使用Java进行开发,但我希望你能找到如何用Java调用COM服务器,例如 - Is there OLE Automation in Java?。见Using Automation to Send a Microsoft Outlook Message。它向您展示了如何使用自动化来创建和发送Microsoft Outlook消息。

另外,您可能会发现How to automate Outlook from another program文章有用。

答案 2 :(得分:0)

我给出了答案

问题出在库路径

我只需要转到Jdeveloper中的库选项并重新选择JAR / Directory中的库