2

Reporting Services 2005 用の独自の配信拡張機能を開発し、これを SaaS マーケティング ソリューションと統合しました。

サブスクリプションを取得し、カスタム パラメーター セットを使用してレポートのスナップショットを取得します。次に、レポートをレンダリングし、リンクとレポートを XLS として添付した電子メールを送信します。

メール配信まで、すべて正常に動作します...

電子メールを送信するための私のコードは次のとおりです。

 public static List<string> SendMail(SubscriptionData data, Stream reportStream, string reportName, string smptServerHostname, int smtpServerPort)
{
  List<string> failedRecipients = new List<string>();

  MailMessage emailMessage = new MailMessage(data.ReplyTo, data.To);
  emailMessage.Priority = data.Priority;
  emailMessage.Subject = data.Subject;
  emailMessage.IsBodyHtml = false;
  emailMessage.Body = data.Comment;

  if (reportStream != null)
  {
    Attachment reportAttachment = new Attachment(reportStream, reportName);
    emailMessage.Attachments.Add(reportAttachment);
    reportStream.Dispose();
  }

  try
  {
    SmtpClient smtp = new SmtpClient(smptServerHostname, smtpServerPort);

    // Send the MailMessage
    smtp.Send(emailMessage);
  }
  catch (SmtpFailedRecipientsException ex)
  {
    // Delivery failed for the recipient. Add the e-mail address to the failedRecipients List
    failedRecipients.Add(ex.FailedRecipient);
  }
  catch (SmtpFailedRecipientException ex)
  {
    // Delivery failed for the recipient. Add the e-mail address to the failedRecipients List
    failedRecipients.Add(ex.FailedRecipient);
  }
  catch (SmtpException ex)
  {
    throw ex;
  }
  catch (Exception ex)
  {
    throw ex;
  }

  // Return the List of failed recipient e-mail addresses, so the client can maintain its list.
  return failedRecipients;
}

SmtpServerHostname の値は localhost、ポートは 25 です。

Telnet を使用して、実際にメールを送信できることを確認しました。そして、それは機能します。

SSRSから取得したエラーメッセージは次のとおりです。

ReportingServicesService!notification!4!08/28/2008-11:26:17:: 通知 6ab32b8d-296e-47a2-8d96-09e81222985c が完了しました。成功: False、ステータス: 例外メッセージ: メールの送信に失敗しました。スタックトレース: C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MailDelivery.cs: 48 行目の MyDeliveryExtension.MyDelivery.Deliver(Notification C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MyDelivery.cs:153 行目、DeliveryExtension: My Delivery、Report: Clicks Development、試行 1 ReportingServicesService!dbpolling!4!08/28/2008-11:26:17 :: NotificationPolling は項目 6ab32b8d-296e-47a2-8d96-09e81222985c の処理を​​終了しました

これは Trust/Code Access Security と関係がありますか?

私の配信拡張機能には、rssrvpolicy.config で完全な信頼が付与されています。

   <CodeGroup 
    class="UnionCodeGroup"
    version="1"
    PermissionSetName="FullTrust"
    Name="MyDelivery_CodeGroup"
    Description="Code group for MyDelivery extension">
    <IMembershipCondition class="UrlMembershipCondition" version="1" Url="C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\bin\MyDeliveryExtension.dll" />
   </CodeGroup> 

ここで信頼が問題になる可能性はありますか?

別の理論: SQL Server と SSRS は、ローカル システムのセキュリティ コンテキストにインストールされました。そうですか、このサービス アカウントはネットワーク リソースへのアクセスが制限されていますか? 独自の SMTP サーバーでさえ?

すべての SQL Server サービス ログオンを管理者に変更しようとしましたが、それでも成功しませんでした。

また、NetworkCredential("Administrator", "password") および NetworkCredential("Administrator", "password", "MyRepServer") を指定して、コードで SMTP サーバーにログオンしようとしました。

誰でもここで助けてもらえますか?

4

5 に答える 5

0

reportStreamを取得する機能をいじくり回した後、メール送信の問題を修正することができました。

エラーはSendMailメソッドではなく、他の場所にありました。ただし、SendMailのコンテキストで例外がスローされました。盗聴!

于 2008-08-28T14:33:50.187 に答える
0
FileStream m_fileStream = null;

m_files = notification.Report.Render(format, null);
RenderedOutputFile m_renderedOutputFile = m_files[0];
m_fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
m_renderedOutputFile.Data.Seek((long)0, SeekOrigin.Begin);
byte[] arr = new byte[(int)m_renderedOutputFile.Data.Length + 1];

m_renderedOutputFile.Data.Read(arr, 0, (int)m_renderedOutputFile.Data.Length);

m_fileStream.Write(arr, 0, (int)m_renderedOutputFile.Data.Length);

m_fileStream.Close();
于 2010-01-14T16:31:47.960 に答える
0

現在の状況:

at MyDeliveryExtension.MailDelivery.SendMail(SubscriptionData data, Stream reportStream, String reportName, String smptServerHostname, Int32 smtpServerPort) 
  in C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MailDelivery.cs:line 48 

at MyDeliveryExtension.MyDelivery.Deliver(Notification notification) 
  in C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MyDelivery.cs:line 153

また、レポート ストリームを破棄しているように見えますが、それはメソッドではなく、そのストリームを開いたものによって行う必要があります (ストリームをアタッチすると破棄されることは明らかではありません)。

例外を再スローする方法が原因で、スタック トレースの一部が失われています。ex 変数をスローしないでください。単にスローするだけで十分です。

この調整を試してください:

public static List<string> SendMail(SubscriptionData data, Stream reportStream, string reportName, string smptServerHostname, int smtpServerPort)
{
  List<string> failedRecipients = new List<string>();

  MailMessage emailMessage = new MailMessage(data.ReplyTo, data.To) {
      Priority = data.Priority,
      Subject = data.Subject,
      IsBodyHtml = false,
      Body = data.Comment
  };

  if (reportStream != null)
    emailMessage.Attachments.Add(new Attachment(reportStream, reportName));

  try
  {
      SmtpClient smtp = new SmtpClient(smptServerHostname, smtpServerPort);

      // Send the MailMessage
      smtp.Send(emailMessage);
  }
  catch (SmtpFailedRecipientsException ex)
  {
    // Delivery failed for the recipient. Add the e-mail address to the failedRecipients List
    failedRecipients.Add(ex.FailedRecipient);

    //are you missing a loop here? only one failed address will ever be returned
  }
  catch (SmtpFailedRecipientException ex)
  {
    // Delivery failed for the recipient. Add the e-mail address to the failedRecipients List
    failedRecipients.Add(ex.FailedRecipient);
  }

  // Return the List of failed recipient e-mail addresses, so the client can maintain its list.
  return failedRecipients;
}
于 2008-08-28T11:57:23.917 に答える
0

reportStream 添付ファイルを削除しようとしました:

  //if (reportStream != null)    
     //emailMessage.Attachments.Add(new Attachment(reportStream, reportName));

そして今、それはうまくいきます。

つまり、reportStream と関係があります。

于 2008-08-28T13:33:52.047 に答える
0

そのため、次のことを避ける必要があります。

catch (Exception ex)
{
    throw ex;
}

それは基本的にあなたの例外を新しいものに隠します。

使用する場合:

catch (Exception ex)
{
    throw; //note: no ex
}

元の例外とスタック トレースが保持されます。

于 2008-08-29T16:43:14.227 に答える