Hey there,
For sending e-mails with a workflow-transition I used the Scriptrunner post function "Send custom e-mail".
Now some user-rights changed in my company.
Via Post-Function I'm not able to use mail.setFrom("mymail@adress,com") in my scripts anymore. But its very important in this project to set a custom e-mail address as sender.
I think from now on I need to send the e-mails as a specific user (with the rights to use the mail.setFrom), so I think I will switch to "custom script post-function".
How can I add a specific user as sender in my custom script?
What I know is this:
def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr)
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)
log.debug("Mail sent")
} else {
log.warn("Please make sure that a valid mailServer is configured")
}
}
How can I change this script to use
1. another Jira-User with the rights to use "mail.setFrom"
or
2. another smtp server with specified user, password, port, etc.
for sending e-mails?
Thank you so much in advance!
If you want a way to send more configureable emails without having to write code, we have an easy UI to configure this kind of thing https://marketplace.atlassian.com/apps/1211069/notification-assistant-for-jira-email?hosting=datacenter&tab=overview
It's working fine for me (Jira 8.5.0 / ScriptRunner 5.6.14.1-p5). Which version of Jira and ScriptRunner are you running?
As a test, I ran this successfully from ScriptRunner's script console:
import com.atlassian.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.jira.component.ComponentAccessor
sendEmail("sender@somewhere.com","recipient@somewhere.com","Test","This is a test.")
def sendEmail(String from,String recipient,String subject,String body)
{
Email email = new Email(recipient)
email.setMimeType("text/html")
email.setFrom(from)
email.setSubject(subject)
email.setBody(body)
SingleMailQueueItem smqi = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(smqi)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.