1 Reply Latest reply on Apr 5, 2016 5:20 PM by WVanSluys1

    How to send emails via jython code though FDMEE with attachments


      I am in the process of trying to code an email notification from FDMEE with attached log files after a load completes.

      After doing lots of research on the web i have a couple of questions regarding where in the jython code i specify the actual log or specific directory i want to pick up my files from.

      I found this code that was nicely put together and am trying to get it to work in eclipse first. I would appreciate some pointers in the right direction as i am completely new to jython.


      Here is what i have:


      def send_email_with_attachment(

      subject, body_text, to_emails,
                                     cc_emails, bcc_emails, file_to_attach):
          import os, string, smtplib, sys
          from email.mime.multipart import MIMEMultipart
          from email.mime.base import MIMEBase
          from email.mime.text import MIMEText
          from email.utils import formatdate
          from email import encoders
          Send an email with an attachment
          header = 'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(C:\Oracle\Middleware\FDMEE\outbox\logs\HFM_100.log)
          # extract server and from_addr from config
          host = "smtp.mydomain.com"
          from_addr = "my.email@somedomain.com"
          # create the message
          msg = MIMEMultipart()
          msg["From"] = from_addr
          msg["Subject"] = subject
          msg["Date"] = formatdate(localtime=True)
          if body_text:
              msg.attach( MIMEText(body_text)
          msg["To"] = ', '.join(to_emails)
          msg["cc"] = ', '.join(cc_emails)
          attachment = MIMEBase('application', "octet-stream")
              attachment.set_payload(open(file_to_attach, "rb").read())
          except IOError:
              msg = "Error opening attachment file %s" % file_to_attach
          emails = to_emails + cc_emails
          server = smtplib.SMTP(host)
          server.sendmail(from_addr, emails, msg.as_string())
      # Email parameters
      to_emails = ["xxxx@xxxxx","xxxxx@xxxxx"]
      cc_emails = []
      bcc_emails = []
      # Get Status
      status = fdmAPI.getProcessStates(fdmContext["LOADID"])
      if str(status["EXPSTATUS"]) == "1":
          subject = "Rule %s executed successfully" % str(fdmContext["RULENAME"])
          body_text = "FDMEE process log has been attached in case you want to review it"
          path = fdmContext["OUTBOXDIR"] + "\\logs\\" + str(fdmContext["TARGETAPPNAME"]) + "_" + str(fdmContext["LOADID"]) + ".log"
          subject = "Rule %s executed with errors" % str(fdmContext["RULENAME"])
          body_text = "Please check FDMEE process log attached"
          path = fdmContext["OUTBOXDIR"] + "\\logs\\" + str(fdmContext["TARGETAPPNAME"]) + "_" + str(fdmContext["LOADID"]) + ".log"
      # Send email
      send_email_with_attachment(subject, body_text, to_emails,cc_emails, bcc_emails, path)

        • 1. Re: How to send emails via jython code though FDMEE with attachments

          Where are you planning to put this script?


          If you want to run this code in Eclipse you will need to temporarily hard any references to fdmAPI and fdmContext or import the fdmee jar files into your lib folder and then add code to connect to your fdmee schema to get the values for:








          review the Admin Guide section -

          Using JAVA IDE to Develop Scripts


          Hope this helps