0

我有一个程序丢失了源代码,现在我们更改了 IP,无法弄清楚我做错了什么。我想要做的是逐步浏览一个表格并让它发送带有相应报告的电子邮件。任何想法出了什么问题?我没有收到任何错误,但也没有收到任何电子邮件(是的,SMTP 服务器可以正常工作)。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Web;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Windows.Forms;

    namespace AutomatedReporting
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {

                DataClasses1DataContext dc = new DataClasses1DataContext();

                foreach (var item in dc.reportsSent1s)
                {
                    string matchedCaseNumber = item.CaseNumberKey;
                    (new MyReportRenderer()).RenderTest(matchedCaseNumber);


                }
                dc.ExecuteCommand("TRUNCATE TABLE reportsSent1");
            }



            public class MyReportRenderer
               {
                     private rs2005.ReportingService2005 rs;
                     private rs2005Execution.ReportExecutionService rsExec;

            public void RenderTest(String matchedCaseNumber)
            {
                string HistoryID = null;
                string deviceInfo = null;
                string encoding = String.Empty;
                string mimeType = String.Empty;
                string extension = String.Empty;
                rs2005Execution.Warning[] warnings = null;
                string[] streamIDs = null;


                rs = new rs2005.ReportingService2005();
                rsExec = new rs2005Execution.ReportExecutionService();
                rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
                rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
                rs.Url = "http://***.***.***.***/ReportServer_DEVELOPMENT/ReportService2005.asmx";
                rsExec.Url = "http://***.***.***.***/ReportServer_DEVELOPMENT/ReportExecution2005.asmx";



                try
                {
                    // Load the selected report.
                    rsExec.LoadReport("/LawDept/LawDeptTIC", HistoryID);

                    // Set the parameters for the report needed.

                    rs2005Execution.ParameterValue[] parameters = new rs2005Execution.ParameterValue[1];
                    parameters[0] = new rs2005Execution.ParameterValue();
                    parameters[0].Name = "CaseNumberKey";
                    parameters[0].Value = matchedCaseNumber;

                    rsExec.SetExecutionParameters(parameters, "en-us");

                    // get pdf of report 
                    Byte[] results = rsExec.Render("PDF", deviceInfo,
                    out extension, out encoding,
                    out mimeType, out warnings, out streamIDs);

                    //pass paramaters for email
                    DataClasses1DataContext db = new DataClasses1DataContext();



                    var matchedBRT = (from c in db.GetTable<vw_ProductClientInfo>()
                                      where c.CaseNumberKey == matchedCaseNumber
                                      select c.BRTNumber).SingleOrDefault();

                    var matchedAdd = (from c in db.GetTable<vw_ProductClientInfo>()
                                      where c.CaseNumberKey == matchedCaseNumber
                                      select c.Premises).SingleOrDefault();



                    var matchedDocument = (from c in db.GetTable<Document>()
                                           where c.DocIDKey == SelectedRow.DocIDKey
                                           select c).SingleOrDefault();

                    db.Documents.DeleteOnSubmit(matchedDocument);
                    db.SubmitChanges();
                    var matchedEmail = (from c in db.GetTable<vw_ProductClientInfo>()
                                        where c.CaseNumberKey == matchedCaseNumber
                                        select c.Email).SingleOrDefault();

                    //send email with attachment
                    MailMessage message = new MailMessage("Reports@acmetaxabstracts.com", matchedEmail, "Report for property located at " + matchedAdd, "Attached is the Tax Information Certificate for the above captioned property");
                    MailAddress copy = new MailAddress("acmetaxabstracts@gmail.com");
                    message.CC.Add(copy);
                    SmtpClient emailClient = new SmtpClient("***.***.***.***");
                    message.Attachments.Add(new Attachment(new MemoryStream(results), String.Format("{0}" + matchedBRT + ".pdf", "BRT")));
                    emailClient.Send(message);

                    //db.reportsSent1s.DeleteOnSubmit(matchedItem);
                    //db.SubmitChanges();
                }

                catch (Exception ex)
                {

                    Console.WriteLine(ex.Message);

                }
            }
        }
        }

    } 
4

0 回答 0