1

我正在尝试通过以下代码发送电子邮件。除了发送的实际电子邮件之外,一切似乎都正常运行。它循环的每条记录我都会收到以下错误。我们必须建立一个新的服务器,从 2003 年到 2008R2 至少可以说很有趣。

在此处输入图像描述

代码如下所示:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using ReportGenerator.rs2005;
using ReportGenerator.rs2005Execution;
namespace ReportGenerator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
        {
            DataClasses1DataContext classes1DataContext = new DataClasses1DataContext();
            foreach (reportsSent entity in classes1DataContext.reportsSents)
        {
            new Form1.MyReportRenderer().RenderTest(entity.CaseNumberKey);
            classes1DataContext.reportsSents.DeleteOnSubmit(entity);
        }
            classes1DataContext.SubmitChanges();
      }
      catch (Exception ex)
      {
        int num = (int) MessageBox.Show(((object) ex.StackTrace).ToString());
      }
        }



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

        public void RenderTest(String matchedCaseNumber)
        {
        string HistoryID = (string) null;
        string DeviceInfo = (string) null;
        string MimeType = string.Empty;
        string Encoding = string.Empty;
        string Extension = string.Empty;
        ReportGenerator.rs2005Execution.Warning[] Warnings = (ReportGenerator.rs2005Execution.Warning[])null;
        string[] StreamIds = (string[]) null;
        this.rs = new ReportingService2005();
        this.rsExec = new ReportExecutionService();
        this.rs.Credentials = CredentialCache.DefaultCredentials;
        this.rsExec.Credentials = CredentialCache.DefaultCredentials;
        this.rs.Url = "http://***.***.***.***/ReportServer_DEVELOPMENT/ReportService2005.asmx";
        this.rsExec.Url = "http://***.***.***.***/ReportServer_DEVELOPMENT/ReportExecution2005.asmx";


            try
            {
                // Load the selected report.
                this.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[] buffer = this.rsExec.Render("PDF", DeviceInfo, out Extension, out MimeType, out Encoding, out Warnings, out StreamIds);
                DataClasses1DataContext classes1DataContext = new DataClasses1DataContext();
                Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>)classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>)(c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>)(c => c.Description)));
                string str1 = Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>) classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>) (c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>) (c => c.Summary)));
                string str2 = Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>)classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>)(c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>)(c => string.Format("{0:C}", (object)c.Total))));
                string str3 = Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>)classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>)(c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>)(c => c.BRTNumber)));
                MailMessage message = new MailMessage("Reports@acmetaxabstracts.com", Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>)classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>)(c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>)(c => c.Email))), "Report for Property " + Queryable.SingleOrDefault<string>(Queryable.Select<vw_ProductClientInfo, string>(Queryable.Where<vw_ProductClientInfo>((IQueryable<vw_ProductClientInfo>)classes1DataContext.GetTable<vw_ProductClientInfo>(), (Expression<Func<vw_ProductClientInfo, bool>>)(c => c.CaseNumberKey == matchedCaseNumber)), (Expression<Func<vw_ProductClientInfo, string>>)(c => c.Premises))), "Tax Information Certificate.");
                MailAddress mailAddress = new MailAddress("acmetaxabstracts@gmail.com");
                ((Collection<MailAddress>)message.CC).Add(mailAddress);
                SmtpClient smtpClient = new SmtpClient("***.***.***.***");
                message.Attachments.Add(new Attachment((Stream)new MemoryStream(buffer), string.Format("{0}" + str3 + ".pdf", (object)"BRT")));
                smtpClient.Send(message);
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show(((object)ex.StackTrace).ToString());

            }
        }
    }
    }
        }
4

0 回答 0