Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

email - Can I send SSRS custom subscription e-mails?

I need to send some e-mails containing a SSRS report to a list of persons, representing the amount of work items they have left until a certain date. What I would like to do is to send each person in the list, the customized report that reflects his progress, so my question is: can I send different reports to the persons in the list (like sending it's e-mail address as a parameter to the report), or can I only send the same report to all people in the list?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you do not have enterprise (to utilize data driven subscription as @StephLocke mentioned), you can programmatically generate SSRS subscriptions using the SSRS web service.

Your code would look something like this (SubscriptionRequest is a custom class I use, its properties should be intuitive):

static void generateSubscription()
{
    if (SubscriptionRequests.Count < 1) return;

    NetworkCredential credentials = new NetworkCredential("user", "pass");
    reports.ReportingService2005 rs = new reports.ReportingService2005();
    rs.Credentials = credentials;
    DateTime topDatetime = DateTime.Now;
    topDatetime = topDatetime.AddMinutes(2);

    foreach (SubscriptionRequest x in SubscriptionRequests)
    {
        reports.ExtensionSettings extensionSettings = new reports.ExtensionSettings();
        List<reports.ParameterValue> extParameters = new List<reports.ParameterValue>();
        List<reports.ParameterValue> parameters = new List<reports.ParameterValue>();
        string description = "Email: ";
        string eventType = "TimedSubscription";
        extensionSettings.Extension = "Report Server Email";

        string scheduleXml = "<ScheduleDefinition><StartDateTime>";
        scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
        scheduleXml += "</StartDateTime></ScheduleDefinition>";

        parameters.Add(new reports.ParameterValue() { Name = "abc", Value = x.id });


        extParameters.Add(new reports.ParameterValue() { Name = "RenderFormat", Value = x.renderFormat });
        extParameters.Add(new reports.ParameterValue() { Name = "TO", Value = x.email });
        extParameters.Add(new reports.ParameterValue() { Name = "ReplyTo", Value = x.replyTo });
        extParameters.Add(new reports.ParameterValue() { Name = "IncludeReport", Value = "True" });
        extParameters.Add(new reports.ParameterValue() { Name = "Subject", Value = "subject - " + " (" + x.id.ToString() + ")" });

        extParameters.Add(new reports.ParameterValue() { Name = "Comment", Value = x.body });
        extensionSettings.ParameterValues = extParameters.ToArray();

        description += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
        description += " (" + x.a + " - " + x.b + " - " + x.c + ")";
        string _reportName = "/report";
        rs.CreateSubscription(_reportName, extensionSettings, description, eventType, scheduleXml, parameters.ToArray());
        topDatetime = topDatetime.AddSeconds(30);
    }           
}  

More examples can be found here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...