我为 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,状态:异常消息:发送邮件失败。Stacktrace:在 C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MailDelivery.cs 中的 MyDeliveryExtension.MailDelivery.SendMail(SubscriptionData data, Stream reportStream, String reportName, String smptServerHostname, Int32 smtpServerPort):第 48 行在 MyDeliveryExtension.MyDelivery.Deliver(Notification通知)在 C:\inetpub\wwwroot\CustomReporting\MyDeliveryExtension\MyDelivery.cs:line 153,DeliveryExtension:我的交付,报告:点击开发,尝试 1 ReportingServicesService!dbpolling!4!08/28/2008-11:26:17 :: NotificationPolling完成处理项6ab32b8d-296e-47a2-8d96-09e81222985c
这可能与信任/代码访问安全有关吗?
我的交付扩展在 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 服务登录更改为管理员 - 但仍然没有任何成功。
我还尝试在我的代码中登录 SMTP 服务器,方法是提供: NetworkCredential("Administrator", "password") 和 NetworkCredential("Administrator", "password", "MyRepServer")
有人可以在这里帮忙吗?