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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

send custom email (like jira email format ) using listener

hello can anyone please give me solution to this ,

i have below information which send in mail using listener but ,

image.png

i want to send mail in below format,

image.png

 

 

1 answer

1 accepted

Hi @Sneha Gole,

For your requirement, if you are using the Send custom email listener, you will need to send the email using the HTML format.

To do so in the listener,  you will need to set the Email format to HTML and format the Email template using the HTML parameters as shown in the image below:-

email_listener.png

 

If possible, could you please share your listener configuration?

Thank you and Kind Regards,

Ram

Hii @Ram Kumar Aravindakshan _Adaptavist_  thank you for your response .

i am using below listener 

image.png

 

and sending mail using ,

MailServerManager mailServerManager = ComponentAccessor.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()

Email email = new Email(issue.getReporter().getEmailAddress())
email.setMimeType("text/html")
email.setTo(to)

def toCC = ""
cc.each
{
toCC = it.toString() + "," + toCC
}
log.warn toCC

// email.setCc(toCC)

// email.setSubject(issue.summary)


// email.setBody(html)
// mailServer.send(email)

Hi @Sneha Gole

If you are using the Custom Listener, you can try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email

def issue = event.issue
def mailServerManager = ComponentAccessor.mailServerManager
def mailServer = mailServerManager.defaultSMTPMailServer
def reporter = issue.reporter
def emailAddress = reporter.emailAddress
def subject = "This is a test mail"
body = """
<html>
<body>
<h1>Subject:</h1>
<h3>Sample Content For Testing Purposes</h3>
</body>
</html>
"""

def email = new Email(emailAddress.toString())
email.setSubject(subject)
email.setBody(body)
email.setMimeType("text/html")
def threadClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = mailServer.class.classLoader
mailServer.send(email)
Thread.currentThread().contextClassLoader = threadClassLoader

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Basically, the text that you want to format should be added to the HTML body, i.e. 

body = """
<html>
<body>
<h1>Subject:</h1>
<h3>Sample Content For Testing Purposes</h3>
</body>
</html>
"""

You will need to trim the text if you want to remove the ending portion of the text. You can use the replace option in the String.

I hope this helps to solve your question. :) 

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you