#1 2018-01-30 10:36:49

aguiral
Member
Registered: 2017-11-30
Posts: 7

Send mail to non RS user people

Hi,

I'm using RS CE (RS3.0.3-6000 (2017-10-25-16-10-52)).

It is possible to send an email to a recipient which us a non RS user ?

Thanks

Alfredo

Offline

#2 2018-01-30 12:16:43

eduardo
Administrator
Registered: 2016-11-01
Posts: 525

Re: Send mail to non RS user people

Hi Alfredo,

this is not directly supported. Since you can send sensible data with reportserver, it is better to know what has been sent and to whom it has been sent. Therefore, we only allow this for reportserver users.

Nevertheless, you can use the "sendTo" functionality for doing whatever you want with your report. This includes sending it directly to an email address, to more than one email address, etc.
More information on the "SendTo" functionality: https://reportserver.net/en/guides/scri … s/Send-To/

An example is:

import java.util.HashMap;

import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook
import net.datenwerke.rs.core.service.sendto.hooks.adapter.SendToTargetProviderHookAdapter
import net.datenwerke.rs.core.client.sendto.SendToClientConfig
import net.datenwerke.rs.core.service.mail.MailService;
import net.datenwerke.rs.core.service.mail.SimpleAttachement;
import net.datenwerke.rs.core.service.mail.SimpleMail;
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService;
import net.datenwerke.rs.core.service.reportmanager.ReportService;
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport;
import net.datenwerke.rs.core.service.reportmanager.engine.config.ReportExecutionConfig;
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report;
import net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorException;
import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook;
import net.datenwerke.rs.scripting.service.scripting.scriptservices.CallbackRegistry;
import net.datenwerke.scheduler.service.scheduler.entities.AbstractJob;
import java.util.HashMap

def HOOK_NAME = "MY_HOOK_NAME"

reportService = GLOBALS.getInstance(ReportService.class)
reportExec = GLOBALS.getInstance(ReportExecutorService.class)
mailService = GLOBALS.getInstance(MailService.class)

String doSendMail(report, values, execConfig) {
  
  try {
		CompiledReport mainReportCompiled = null;
		
        if (execConfig != null) {
			mainReportCompiled = reportExec.execute(report, "EXCEL", execConfig);
        } else {
            mainReportCompiled = reportExec.execute(report, "EXCEL", ReportExecutionConfig.EMPTY_CONFIG);
        }


		SimpleMail mail = mailService.newSimpleMail();
		mail.setSubject("Testreport von SendMail.java");
		mail.setToRecipients("test@reportserver.net");
		mail.setFrom("from@reportserver.net");

		SimpleAttachement mainReportAttachement = new SimpleAttachement(mainReportCompiled.getReport(),
				mainReportCompiled.getMimeType(), "myfile.xlsx");
		mail.setContent("Test", mainReportAttachement);

		// send mail
		mailService.sendMail(mail);

		return "Send the report via mail. Config " + values;
    
    } catch (ReportExecutorException e) {
			e.printStackTrace();
	}
}


def callback = [
  consumes : { report ->
    def config = new SendToClientConfig();
    config.setTitle("Send via script");
    return config;
  },
  getId : { ->
    return "someUniqueIdA"
  },
  sendTo : { report, values, execConfig ->
  	return this.doSendMail(report, values, execConfig);
  },
  
  scheduledSendTo: { compiledReport, report,
			format, values,
			execConfig ->
	return this.doSendMail(report, values, execConfig);
  }

] as SendToTargetProviderHookAdapter

GLOBALS.services.callbackRegistry.attachHook(HOOK_NAME, SendToTargetProviderHook.class, callback)

Regards,
Eduardo

Offline

#3 2018-01-30 15:22:58

aguiral
Member
Registered: 2017-11-30
Posts: 7

Re: Send mail to non RS user people

Thank you very much Eduardo.

Offline

Board footer

Powered by FluxBB