Skip to Content
0

Sending Mail from UDF

Jul 17, 2017 at 09:32 AM

55

avatar image
Former Member

Hi Community members,

I have a requirement to send mail from UDF. I tried this from message mapping by using java code from UDF. It is working and i got the mail. Is this good practice to this? I can get the host,to,from list dynamic by using parameterized mapping.

http://docs.oracle.com/javaee/6/api/javax/mail/package-summary.html

 Properties props = new Properties();
    props.put("mail.smtp.host", "my-mail-server");
    props.put("mail.from", "me@example.com");
    Session session = Session.getInstance(props, null);

    try {
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom();
        msg.setRecipients(Message.RecipientType.TO,
                          "you@example.com");
        msg.setSubject("JavaMail hello world example");
        msg.setSentDate(new Date());
        msg.setText("Hello, world!\n");
        Transport.send(msg);
    } catch (MessagingException mex) {
        System.out.println("send failed, exception: " + mex);
    }

Please suggest.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Jul 17, 2017 at 10:00 AM
0

it is SFTP to File, i need to do soap look up, while key presents in cloud system then, i dont have to send the mail. when it is not there, i have to trigger the mail to distribution list.

we are migrating few interfaces from MQ. there they are sending mails from javacode. IT architect is asking us to follow the same.

Its not a good practice calling Mail API in mapping because what if your original request is not delivered to target system due to some connectivity issue even though in that case your mail will be triggered.
>> it is ok for us. since two processes are not bound together.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

This look fine . If your mail is just to notify about the key and not the delivery of the message then it looks good.

1
Manoj K Jul 17, 2017 at 09:49 AM
4

Hi,

What is end to end scenario ?

Its not a good practice calling Mail API in mapping because what if your original request is not delivered to target system due to some connectivity issue even though in that case your mail will be triggered.

So usually it better to have 2 OM .first one being the original and then the second one for your mail interface and then you can have "Maintain Order At RunTime" so that mail interface will be triggered only once the first flow is successfull.

Br,

Manoj

Share
10 |10000 characters needed characters left characters exceeded