문제

나는 이것을 SaaS 마케팅 솔루션과 통합하기 위해 Reporting Services 2005를위한 나만의 배송 확장을 개발했습니다.

구독이 필요하고 사용자 정의 매개 변수 세트로 보고서의 스냅 샷을 가져옵니다. 그런 다음 보고서를 렌더링하고 링크와 XL로 첨부 된 보고서와 함께 이메일을 보냅니다.

메일 배송까지 모든 것이 잘 작동합니다 ...

다음은 이메일을 보내기위한 내 코드입니다.

 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! 알림! 4! 4! 08/28/2008-11 : 26 : 17 :: 알림 6AB32B8D-296E-47A2-8D96-09E8122985C 완료. 성공 : False, Status : 예외 메시지 : 실패 메일 보내기. stacktrace : at myDeliveryExtension.MailDelivery.SendMail (subscriptionData 데이터, 스트림 보고서, 문자열보고 이름, String smptserverHostName, int32 smtpserverport)에서 c : inetpub wwwroot customReporting myDeliverTension MailDelveliver.cs : line 48 at mydeliveriviction (at mydeliverdeliveri). 알림) C : inetpub wwwroot Custom Reporting Mydeliveryextension Mydelivery.cs : 라인 153, Deliveryextension : My Deliverys, Report : Clicks Development, DBPOLLING! 4! 4! 08/28/2008-11 : 26 : 17 :: NotificationPolling 완료된 처리 항목 6AB32B8D-296E-47A2-8D96-09E8122985C

신뢰/코드 액세스 보안과 관련이있을 수 있습니까?

내 배송 연장은 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")을 통해 Code에서 SMTP 서버에 로그인을 시도했습니다.

누구든지 여기서 도와 줄 수 있습니까?

도움이 되었습니까?

해결책

무엇입니까 :

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

또한 보고서 스트림을 처분하는 것처럼 보이지만, 이는 당신의 방법이 아니라 그 스트림을 열었던 것에 의해 수행되어야합니다 (스트림을 첨부하는 것이 그것을 처리하는 것은 분명하지 않습니다).

예외를 재발하는 방법으로 인해 스택 추적의 일부를 잃고 있습니다. 전 변수를 던지지 마십시오. 던지면 충분합니다.

이 조정을 시도하십시오.

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;
}

다른 팁

ReportStream 첨부 파일을 제거하려고했습니다.

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

그리고 지금은 잘 작동합니다.

따라서 보고서와 관련이 있습니다.

보고서를 얻는 Tunctionality를 속인 후, 나는 메일 보내기 문제를 해결할 수있었습니다.

오류는 Sendmail 메소드에 있지 않았지만 다른 사람은 다른 사람입니다. 그래도 Sendmail의 상황에서 예외가 발생했습니다. 버거!

그렇기 때문에 피해야합니다.

catch (Exception ex)
{
    throw ex;
}

그것은 기본적으로 새로운 예외에서 예외를 망쳐 놓습니다.

사용하는 경우 :

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

원래 예외와 스택 추적을 유지합니다.

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top