【问题标题】:CDO.Message giving "Access denied" on Windows Server 2008CDO.Message 在 Windows Server 2008 上给出“拒绝访问”
【发布时间】:2009-12-03 23:39:25
【问题描述】:

我有一个经典的 ASP 页面,它创建一个 CDO.Message 对象来发送电子邮件。该代码适用于 Window Server 2003,但不适用于 2008。在 2008 年,会引发“访问被拒绝”错误。这是我为诊断问题而编写的一个简单的测试页面。我怎样才能让它在 Windows Server 2008 上运行?


dim myMail
Set myMail=CreateObject("CDO.Message")
If Err.Number <> 0 Then
    Response.Write ("Error Occurred: ")
    Response.Write (Err.Description)
Else
    Response.Write ("CDO.Message was created")
    myMail.Subject="Sending email with CDO"
    myMail.From="sender@mycompany.com"
    myMail.To="recipient@mycompany.com"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
End If

【问题讨论】:

    标签: windows-server-2008 cdo.message


    【解决方案1】:

    我从来没有让 CDO.Message 对象在 Windows Server 2008 上工作。但是,我找到了一种解决方法。我写了一个适用于 Windows Server 2008 的电子邮件类。希望这对其他人有帮助。

    [ComVisible(true)]
    public class Email
    {
        public bool SendEmail(string strTo, string strFrom , string strSubject, string strBody)
        {
            bool result = false;
    
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient client = new SmtpClient("smtp.mycompany.com");
    
                List<string> to = recipientList(strTo);
                foreach (string item in to)
                {
                    message.To.Add(new MailAddress(item));
                }
                message.From = new MailAddress(strFrom);
                message.Subject = strSubject;
                message.Body = strBody;
    
                client.Send(message);
    
                result = true;
            }
            catch
            {
                result = false;
                throw;
            }
            return result;
        }
    
        private List<string> recipientList(string strTo)
        {
            List<string> result = new List<string>();
            string[] emailAddresses = strTo.Split(new Char[]{',',';'});
            foreach (string email in emailAddresses)
            {
                result.Add(email.Trim());
            }
            return result;
        }
    }
    

    【讨论】:

      【解决方案2】:

      只要您使用 Microsoft SMTP 服务器(1),您就可以使用 IIS 元数据库资源管理器为 IIS_USRS 组(2) 授予对 /LM/SmtpSvc/ 和 /LM/SmtpSvc/1/ 的读取权限IIS 元数据库中的节点。

      不幸的是,此解决方案不适用于 Windows 7。Microsoft 在 Windows 7 中提供 SMTP 服务器,因此如果不重构代码就很难解决此问题。

      (1) 见http://www.itsolutionskb.com/2008/11/installing-and-configuring-windows-server-2008-smtp-server

      (2) 见http://blogs.msdn.com/b/akashb/archive/2010/05/24/error-cdo-message-1-0x80040220-the-quot-sendusing-quot-configuration-value-is-invalid-on-iis-7-5.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-18
        • 2011-02-28
        • 1970-01-01
        • 1970-01-01
        • 2010-09-17
        • 1970-01-01
        • 2022-08-10
        • 1970-01-01
        相关资源
        最近更新 更多