This discussion is archived
6 Replies Latest reply: Sep 12, 2013 4:00 AM by User_Apr RSS

Adf Mail with Attachment

User_Apr Newbie
Currently Being Moderated

Hi Experts,

 

 

 

 

i'm Using Jdeveloper 11.1.1.5.0.

 

 

 

My Scenario is to send a mail with Attachments from Adf Application.

 

 

I have sent a Mail Without attachment from Adf Application, it works fine.

 

 

But, it have to send a mail with Attachment.

 

 

 

 

 

 

Anyone Guide me

  • 2. Re: Adf Mail with Attachment
    User_Apr Newbie
    Currently Being Moderated

    Thank for your Reply

    I'm Using Jdeveloper 11.1.1.5.0

     

     

    I am   using the following Code for send a mail without Attachment from Adf Application.

     

    Mail Sent Successfully.

    Code:

        public String send(String SMTPhost, String From,   String To,   String Subject,  String Body,  String Attachment,  String Username,   String Password,    String Port, String filename1)

        {

                              String  to= To, subject = Subject , from = From ,

                              cc = null, bcc = null,  url =null;

                              String mailhost = SMTPhost;

                              String  user = Username , password = Password;

                              boolean debug = false;

                              boolean verbose = false;

                              boolean auth = true;

                              String prot = "smtp";

                              try{

                                 

                                  String filename = System.getProperty("java.home")+"/lib/security/cacerts".replace('/', File.separatorChar);

                                  String password2 = "xxxxxxxxx";

                                  System.setProperty("javax.net.ssl.trustStore",filename);

                                  System.setProperty("javax.net.ssl.trustStorePassword",password2);

                             

                             

                              Properties props = System.getProperties();

                             

                              props.put("mail." + prot + ".host", mailhost);       

                              props.put("mail." + prot + ".auth", "true");

                              props.put("mail.smtp.starttls.enable", "true");

                              props.put("mail.smtp.port", Port);

                             

                             

                              // Get a Session object

                              Session session = Session.getInstance(props, null);

                              if (debug)

                                  session.setDebug(true);

                              Message msg = new MimeMessage(session);

                              if (from != null)

                                  msg.setFrom(new InternetAddress(from));

                             

                      

                              msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));

                              if (cc != null)

                                  msg.setRecipients(Message.RecipientType.CC,

                                                          InternetAddress.parse(cc, false));

                              if (bcc != null)

                                  msg.setRecipients(Message.RecipientType.BCC,

                                                          InternetAddress.parse(bcc, false));

                                

                              msg.setSubject(subject);

                      

                              String text = Body;

                              msg.setText(text);

                                  MimeBodyPart messageBodyPart = new MimeBodyPart();

                                  String filename2 = "D://" + filename1;

                                      System.out.println("Exact path--->" + filename2);

                                      DataSource source = new FileDataSource(filename2);

                                      messageBodyPart.setDataHandler(new DataHandler(source));

                                      messageBodyPart.setFileName(filename2);

     

     

     

     

                                  Multipart multipart = new MimeMultipart(filename1);

                                  multipart.addBodyPart(messageBodyPart);

                                  msg.setContent(multipart);

                                 

                                    SMTPTransport t =

                                  (SMTPTransport)session.getTransport(prot);

                              try {

                                  if (auth)

                                      t.connect(mailhost, user, password);           

                                      t.sendMessage(msg, msg.getAllRecipients());

                                 

                              }

                             

                              finally {

                                  if (verbose)

                                      System.out.println("Response: " + t.getLastServerResponse());

                                  t.close();

                              }

                                 

                              FacesMessage fm = new FacesMessage("Mail has been sent successfully.");

                              fm.setSeverity(FacesMessage.SEVERITY_INFO);

                              FacesContext af = FacesContext.getCurrentInstance();

                              af.addMessage(null, fm);

                              System.out.println("\nMail was sent successfully.");

                              }

                              catch(Exception e){

                                  e.printStackTrace();

                              }

                             

           

        return "Success";

        }

     

     

        public String SendMail() {

           send(SMTPhost, From, To, Subject, Body, Attachment, Username, Password, Port,filename1);

            return null;

        }

     

     

    But, it throws exception while sending with  attachments.


    java.io.IOException: No content

      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:930)

      at com.rits.suplr.view.backing.Mail.send(Mail.java:169)

      at com.rits.suplr.view.backing.Mail.SendMail(Mail.java:193)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at 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 org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)

      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

      at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)

      at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:148)

      at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:102)

      at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)

      at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)

      at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)

      at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:96)

      at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:902)

      at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:313)

      at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:186)

      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)

      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)

      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)

      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)

      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)

      at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)

      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)

      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)

      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)

      at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:175)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)

      at java.security.AccessController.doPrivileged(Native Method)

      at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)

      at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)

      at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)

      at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)

      at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)

      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)

      at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)

      at 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)

      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)

      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)

      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)

      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)

      at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)

     

    Anyone Guide Me

  • 3. Re: Adf Mail with Attachment
    Cvele_new_account Expert
    Currently Being Moderated

    Did you follow links I provided you ?

  • 4. Re: Adf Mail with Attachment
    User_Apr Newbie
    Currently Being Moderated

    Ya.I Tried. its Not Working For Me.

     

     

     

     

    Any one Guide Me

  • 5. Re: Adf Mail with Attachment
    Cvele_new_account Expert
    Currently Being Moderated

    From which exactly  link/code you are getting above error ?
    I do not see that you are tried with any of that...

  • 6. Re: Adf Mail with Attachment
    User_Apr Newbie
    Currently Being Moderated

    thank you for your replay

     

    i Saw the Link Which you send for  Mail  with Attachment.its a

    Jdeveloper,Oracle ADF & Java: Gmail Integration with Oracle ADF using Java Mail 

     

     

     

    Note:I'm using Jdeveloper 11.1.1.5.0 Release1.

     

     

    How To achieve the Mail With Attachment in Release1

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points