Forums

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

How to send an e-mail from a specific user?

Z1N590
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!
May 15, 2020

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!

 

2 answers

0 votes
Boris Berenberg - Atlas Authority
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2020

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

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2020

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)
}

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events