Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can send email using jira JAVA API?

Ramesh Lakshmanasamy November 8, 2018

i configured SMTP in jira but when i am trying to send email smtp always null.also email object "from" return null

Example code:

Email em = new Email("bscitramesh@gmail.com");
System.out.println("em;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"+em);
em.setSubject("Example Subject");

em.setBody("Hello");

em.setEncoding("text/plain");

SingleMailQueueItem smqi = new SingleMailQueueItem(em);
System.out.println("smqi;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"+smqi);
ComponentAccessor.getMailQueue().addItem(smqi);

2 answers

1 accepted

1 vote
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2018

Hi @Ramesh Lakshmanasamy

Here is a working example for custom email with Jira JAVA API

import com.atlassian.mail.Email;
import com.atlassian.mail.queue.SingleMailQueueItem;

Email email = new Email("email_address@company.com");
email.setCc("another_email_address@company.com");
email.setFromName("what ever you want");
email.setSubject("what ever you want");
email.setBody("what ever you want");
email.setMimeType("text/html");
SingleMailQueueItem smqi = new SingleMailQueueItem(email);
ComponentAccessor.getMailQueue().addItem(smqi);

 

Note that "setCc" and "setFromName" are not mandatory, you can remove these rows if you don't want them.

 

You can check your mail queue in Jira to make sure your code works and email are going to the queue.

If the email not sending then you configured the mail server wrong.

 

Try the code, check if you see the mail in the queue, and/or it being sent.

Let me know the outcome. 

Ramesh Lakshmanasamy November 11, 2018

Thanks for your reply its working fine

0 votes
Juan Jose
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 30, 2020

hi guys, does someone has an example of How I can send an outlook event "Appointment" from JIRA? 

robert_egan_305 September 2, 2021

Not an example, but a hint.

setMultipart(javax.mail.Multipart appointment)

There are multiple examples of the format scattered around the internet...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events