Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sending custom mail from plugin JIRA Core 7.7.1

vmonakhov July 12, 2018

Hi!

I'm trying to send custom email from plugin using JIRA Core 7.7.1 and  SDK-6.3.10.

Using code from https://community.atlassian.com/t5/Answers-Developer-Questions/jira-7-send-email-plugin-development/qaq-p/469543 doesn't help, because I can't figure out how to import class SingleMailQueueItem. Tryed add to pom.xml dependency:

<dependency>
    <groupId>com.atlassian.mail</groupId>
    <artifactId>atlassian-mail</artifactId>
    <version>2.8.6</version>
</dependency>

helps to build plugin without errors through atlas-run command, but JIRA web page returns HTTP ERROR 404 and stops write log on "Type Ctrl-C to exit" row.

Can somebody explain, how to import SingleMailQueueItem correctly, or give working example of send mail code?

1 answer

1 accepted

1 vote
Answer accepted
lasrik
Contributor
July 18, 2018

This is a working example from one of my plugins:

import com.atlassian.jira.mail.Email;
import com.atlassian.mail.queue.SingleMailQueueItem;
import com.atlassian.mail.queue.MailQueue;
import com.atlassian.jira.user.ApplicationUser;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.MessagingException;

// constructor injected
private final MailQueue mailQueue;

try
{
Email email = createMail(user, payload);
SingleMailQueueItem item = new SingleMailQueueItem(email);
mailQueue.addItem(item);
log.debug("Queued email notification {} to {}.", payload.getShortName(), user.getEmailAddress());
} catch (Exception ex) {
log.error("Error while sending email notification:", ex);
}
}

...

protected Email createMail(ApplicationUser user, Payload payload) throws MessagingException, IllegalArgumentException {
Email email = new Email(user.getEmailAddress(), null, EMAIL_BCC);
email.setSubject(renderSubject(payload, user));
email.setFromName("Jira Service (JIRA)");
email.setFrom(defaultFromAddress);
email.setEncoding("utf-8");
MimeMultipart root = generateMimeMultipartMail(payload, user);
email.setMultipart(root);
return email;
}

In my pom.xml I only have these two dependencies:

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>

 No explicit reference to atlassian-mail - it's included in jira-api

vmonakhov July 23, 2018

Hi Tobias,

Can you also write what classes you import for this code?

lasrik
Contributor
July 23, 2018

I have added the imports in the above example

vmonakhov July 26, 2018

Hi Tobias,

Finally I made it with your code, thank you!

Suggest an answer

Log in or Sign up to answer