I want to define a job in Scriptrunner to send a rendered page body via email every day.
But I can't get page body rendered and set it to email body
Anyone can help me?
thanks
import com.atlassian.confluence.renderer.UserMacroLibrary
import com.atlassian.confluence.core.BodyContent
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.mail.Email;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.confluence.mail.ConfluenceMailServerManager
def pageMangaer = ComponentLocator.getComponent(PageManager)
def bodyContent = ComponentLocator.getComponent(BodyContent)
def userMacroLibrary = ComponentLocator.getComponent(UserMacroLibrary)
def page = pageMangaer.getPage("SpaceKey","PageTitleORPageID")
def confluenceMailServerManager = ComponentLocator.getComponent(ConfluenceMailServerManager)
SMTPMailServer mailServer = confluenceMailServerManager.getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email("user@domain.com");
email.setSubject("PageTitle");
email.setBody(page);
mailServer.send(email);
} else {
throw new RuntimeException("no mail server!!!");
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.