If JIRA or Confluence already have smtp configured then how to use those settings to send email from a plugin?
Community moderators have prevented the ability to post new answers.
Event is one solution. You can also send email directly without trigger by using SMTPMailServer.
JIRA pseudo code:
SMTPMailServer mailServer = MailFactory.getServerManager().getDefaultSMTPMailServer(); if (NotificationRecipient.MIMETYPE_HTML.equalsIgnoreCase(prop.getProperty(messageTypeKey))) mailServer.send(new Email(to.getEmailAddress()).setSubject(subject).setBody(message).setMimeType(Constants.NOTIFICATION_MIME_TYPE_HTML)); else mailServer.send(new Email(to.getEmailAddress()).setSubject(subject).setBody(message).setMimeType(Constants.NOTIFICATION_MIME_TYPE_TEXT));
You can just use the 'ConfluenceMailQueueItem' class within your plugin.
Here is my example with groovy:
{groovy:output=wiki} import com.atlassian.confluence.mail.template.ConfluenceMailQueueItem; def toAddress="user@company.com"; def subject="testmail"; def body="some body"; def mimeType="text/html"; ConfluenceMailQueueItem mail = new ConfluenceMailQueueItem(toAddress, subject, body, mimeType); mail.send(); println "mail successful send"; {groovy}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
where to put this code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And here is an example using the mail queue:
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer() email.setFrom(mailServer.getDefaultFrom()) email.setSubject("email subject") email.setMimeType(emailFormat == "HTML" ? "text/html" : "text/plain") email.setBody("the body") SingleMailQueueItem item = new SingleMailQueueItem(email) ManagerFactory.getMailQueue().addItem(item)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just a note: ManagerFactory been deprecated since JIRA 4.2. Use ComponentAccessor.getMailQueue().addItem(item); instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The easiest way, I think, is to fire a new event from the plugin and create a mail notification for the event. You can create your own mail templates for each event.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Somehow in subject line "[JIRA]" gets added. How do I remove it? With
email.setSubject("email subject")
when I get email subject line is "[JIRA] email subject"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
All of them are right answer. So I marked the 3 as acceptable answer. Others were equally correct.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
a solution for Confluence is available here : http://blog.k15t.com/sending-email-from-confluence-plugins
I think it should not be too hard to adapt it to Jira since there are quite a few MailQueueItem factories available in the API, but I haven't tried anything in Jira.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Link is broke :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.