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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.