Forums

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

[Resolved] sending emails from JIRA using queue and API functions

Maciej Łukasz Wojszkun August 17, 2021

Hi everyone, 

is here someone, who fight with JIRA API for sending emails? I have problems with attachments, they're always as in-line. Thunderbird have problem with show it, on gmail or apple mail I can see them, but just below message body. 

Here some code: (I use jython...)

from com.atlassian.jira.component import ComponentAccessor
from com.atlassian.jira.mail import Email
from com.atlassian.jira.mail.builder import EmailBuilder
from com.atlassian.jira.mail.util import MailAttachments
from com.atlassian.jira.notification import NotificationRecipient
ap = ComponentAccessor.getApplicationProperties()

authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
currentUser = authenticationContext.getLoggedInUser()
mq = ComponentAccessor.getMailQueue()
am = ComponentAccessor.getAttachmentManager()
recipient = NotificationRecipient(currentUser)
email = Email(currentUser.getEmailAddress())
lm = ComponentAccessor.getLocaleManager()

issuekey = issue.getKey()
issueUrl = ap.getString("jira.baseurl") + "/browse/" + issuekey

subject = "Update in " + issue.getKey()
body = """Here is update from <a href="%(issueUrl)s">%(issuekey)s</a>.
Below you find attachments.
\n

""" % { "issuekey": issuekey, "issueUrl": issueUrl }

attachments = issue.getAttachments()
emailAttachments = []
for attachment in attachments:
emailAttachments.append(MailAttachments.newMailAttachmentByStreamingFromAttachmentManager(attachment,am).buildBodyPart())

#newEmail = EmailBuilder(email,NotificationRecipient(currentUser)).withBody(body).withSubject(subject).addAttachments(emailAttachments)
newEmail = EmailBuilder(email,"text/html",lm.getLocaleFor(currentUser)).withBody(body).withSubject(subject).addAttachments(emailAttachments)

queueItem = newEmail.renderNowAsQueueItem()

 

1 answer

1 accepted

0 votes
Answer accepted
Maciej Łukasz Wojszkun August 18, 2021

well, i found resolution :P

i = 0
while i < len(attachments):
emailAttachments[i].setDisposition("attachment")
emailAttachments[i].setFileName(attachments[i].getFilename())
i += 1

Suggest an answer

Log in or Sign up to answer