Skip to Main Content

Analytics Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to send emails via jython code though FDMEE with attachments

2886698Mar 30 2016 — edited Apr 5 2016

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")
    try:
        attachment.set_payload(open(file_to_attach, "rb").read())
        encoders.encode_base64(attachment)
        attachment.add_header(*header)
        msg.attach(attachment)
    except IOError:
        msg = "Error opening attachment file %s" % file_to_attach
        fdmAPI.logError(msg)
        sys.exit(1)
    emails = to_emails + cc_emails
    server = smtplib.SMTP(host)
    server.sendmail(from_addr, emails, msg.as_string())
    server.quit()
# 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"
else:
    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)

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2016
Added on Mar 30 2016
1 comment
1,710 views