Change sender of sendEmail - scriptrunner

Dan27 December 2, 2019

Hello,

 

I want to change the sender of sendEmail I did in Groovy.

this is my code:

def sendEmail(String emailAddr, String subject, String body) {
//MailServerManager mailServerManager = ComponentAccessor.getMailServerManager();
def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();

//if (mailServer) {
try{
Email email = new Email(emailAddr)
email.setMimeType("text/html")
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)
log.debug("Mail sent")
}

catch(Exception e) {
log.warn("Please make sure that a valid mailServer is configured")
log.warn e;
}
}

 

In additional, I want to remove the beggining od the mail "[Jira]".

 

How can I do it?

Thank you,

Daniel

1 answer

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.
December 2, 2019

The Email class has setFrom() and setFromName() methods.

https://docs.atlassian.com/atlassian-mail/1.3.23/com/atlassian/mail/Email.html

You can remove the [Jira] prefix from ALL outbound email messages by going into the Outgoing Mail settings page, but I don't know that you can remove it for specific messages in a script.

Dan27 December 4, 2019

Thank you @Payne , the setFrom function worked like a charm! :)

Omar LOUNES May 12, 2021

Hello @Dan27  

For the prefix [JIRA], you can remove it by setting the prefix to the mail server  

mailServer.SetPrefix("")

Like Davida likes this

Suggest an answer

Log in or Sign up to answer