How do I write a Java program to send a custom notification email via Agile PLM?

How do I write a Java program to send a custom notification email via Agile PLM?
I am new to Java but not new to Agile PLM as a regular user.  My first time scripting with it.
Thanks in Advance!

No Files Were Attached
Galactus3000 Agile User Asked on November 29, 2018 in IT and Networking.
Add Comment
2 Answer(s)
Best answer

Hi Galactus3000,

This is how i would suggest you to proceed. Please bear with me if some of the details seems elementary.  You can use this code and test it or google up sample code and integrate in your existing solutions be it PX or SDK based utilities.

1. Step 1 : Open your Project you have setup in your IDE(in my case it is Eclipse) and add external jar in build path of your project. In my case i am using  “mail.jar”. 
2. Scenario : Let’s say i have to sent a mail to my Change analyst after certain activity is completed in Agile.  Let’s say the mail id of my change analyst is ChgAnalyst@myorg.com
3.

// Making a call to my method sending mail by passing following parameters
String msgBody=
“<b> Please Note: </b> “+ “This is sample mail”;
String msg  =
“Demo Mail”;
MailServer=
“You can enter your mail server detail here”; //e.g. smtp.myorg.com
mailFrom=
“GenericMailId@Server.com” //You can configure a mail id specific for the purpose. The last parameter i have set as blank which you can use to p

//Calling My Sample Mail Method

sendMail(mailServer, mailFrom, “ChgAnalyst@myorg.com“, msgSubject, msgBody, “”);

//body of mail looks like this for me

    public static boolean sendMail(String mailServer, String from, String to, String title, String body,
            String fileAttachment) {

        // create some properties and get the default Session
        Properties props = new Properties();
        props.put(“mail.smtp.host”, mailServer);
        Session session = Session.getDefaultInstance(props, null);
        try {
            // create a message
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = { new InternetAddress(to) };
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(title);
            msg.setSentDate(new java.util.Date());
            // create and fill the first message part
            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(body);
            mbp1.setContent(body, “text/html”);
            // create and fill the second message part with attachment

            // create the Multipart and its parts to it
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);

            // Test for file attachment = empty string
            if (!fileAttachment.equals(“”)) {
                MimeBodyPart mbp2 = new MimeBodyPart();

                DataSource source = new FileDataSource(fileAttachment);
                mbp2.setDataHandler(new DataHandler(source));
                String value = “”;// remove directory from file name
                value = fileAttachment.substring(3);
                mbp2.setFileName(value);

                mp.addBodyPart(mbp2);
            }

            // add the Multipart to the message
            msg.setContent(mp);
            // send the message
            Transport.send(msg);
        } catch (MessagingException mex) {
            mex.printStackTrace();
            Exception ex = null;
            if ((ex = mex.getNextException()) != null) {
                ex.printStackTrace();
            } // end if
            // err_flag = true;
        } // end try catch
        return true;

    }

———————————————————————————–

Regards,
Arif
Arif Agile Angel Answered on November 29, 2018.
Add Comment

Hi,

If the email you are trying to send is related to PLM Object information, you can define a custom notification in Agile JavaClient and invoke the notification from Java using APIs.

I am not a developer hence will not be able to provide code snippets.  Please check the SDK Guide.

Thanks,
Sankar.

Sankar Sakthivel Agile Angel Answered on December 1, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.