Sending emails from Job

Description
dan7777777
Posts: 5
Joined: Wed May 17, 2017 5:08 pm

Sending emails from Job

Postby dan7777777 » Mon Jul 24, 2017 2:54 pm

Hello,
I have been attempting to write a Job extension that automatically gathers data from some work items and then emails that information to a list of users. I have been able to write workflow functions that sends automated emails, but when I use the same code inside of a Job extension, there is an error with the messages not being able to be sent. The code that I have been using uses Java mail, so I have also tried the code that is shown in the examples SDK using the Announcement API, but there are problems sending emails with that as well. Is there a certain setting somewhere in the configuration file that denies messages to be sent via Job? Any information on this would be extremely helpful. Here is a code snippet of my notification method:

Code: Select all

IAnnouncerService announcerService = (IAnnouncerService) PlatformContext.getPlatform().lookupService(IAnnouncerService.class);
           
StringBuilder contentBuilder = new StringBuilder();
contentBuilder.append(body);       
           
Announcement announcement = new Announcement();
announcement.setSender(NOTIFICATION_DEFAULT_SENDER);
announcement.setReceivers(new String[] {recipient});
announcement.setContentType("text/html");
announcement.setSubject(subject);
announcement.setContent(contentBuilder.toString());
try {
     announcerService.sendAnnouncement(IAnnouncerService.SMTP_TRANSPORT, announcement);
     timestamp = new Timestamp(System.currentTimeMillis());
     System.out.println(timestamp + " Message sent to " + recipient);
} catch (Exception ex) {
      timestamp = new Timestamp(System.currentTimeMillis());
   System.out.println(timestamp + " Message failed to send.");
    System.out.println(timestamp + " " + ex.toString());
   }

martins
Posts: 178
Joined: Thu Nov 05, 2009 3:24 pm

Re: Sending emails from Job

Postby martins » Tue Aug 01, 2017 2:13 pm

We use Javascript for some jobs to send email notification.

The following Javascript code works fine for me:

Code: Select all

var anonservice = com.polarion.platform.core.PlatformContext.getPlatform().lookupService(com.polarion.platform.announce.IAnnouncerService.class);
var anon = new com.polarion.platform.announce.Announcement();
anon.setSender(com.polarion.platform.announce.NOTIFICATION_DEFAULT_SENDER);
anon.setReceivers(["someone@somewhere.com"]);
anon.setSubject("Test Title");
anon.setContentType("text/html");
anon.setContent("this is just a <b>TEST</b>");
anonservice.sendAnnouncement("smtp", anon);

Martin

dan7777777
Posts: 5
Joined: Wed May 17, 2017 5:08 pm

Re: Sending emails from Job

Postby dan7777777 » Wed Aug 02, 2017 4:45 pm

I am still getting the same error as I would by doing it through java. The specific error i get (whether its through java or javascript) is
'Exception occurred during job unit execution: java.lang.Exception: Error while sending announcement to (recipient), Subject: Test title'
I get this error when I use the announcer API but when I use the other method of sending emails through java mail the specific error is
'can only send rfc 2822 messages'

This is why I think it may be some kind of polarion or server config, but what confuses me is the fact that this works from the context of a workflow function. Is there anything I am missing?

martins
Posts: 178
Joined: Thu Nov 05, 2009 3:24 pm

Re: Sending emails from Job

Postby martins » Tue Aug 08, 2017 12:25 pm

Googling for "can only send rfc 2822 messages" gives as first result:
"Address in mailbox given does not comply with RFC 2822"

So it looks like there's a problem with the email address you are trying to send the email to.
Try to use an address in the format "name@domain.com".

Martin

dan7777777
Posts: 5
Joined: Wed May 17, 2017 5:08 pm

Re: Sending emails from Job

Postby dan7777777 » Tue Aug 08, 2017 7:31 pm

This is definitely not the problem, I have tried multiple, verified email addresses and I still get this error. Though, I tested your suggestion regardless just in case. The same code and email works from one side of the system but not in this.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: Google [Bot] and 2 guests