CDO.消息给出“访问被拒绝”在 Windows Server 2008 上

发布于 2024-08-13 05:35:01 字数 875 浏览 7 评论 0原文

我有一个经典 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="[email protected]"
    myMail.To="[email protected]"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
End If

I have a Classic ASP page that creates a CDO.Message object to send email. The code works on Window Server 2003 but not 2008. On 2008 an "Access is denied" error gets thrown. Here is a simple test page I wrote to diagnose the problem. How can I get this to work on 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="[email protected]"
    myMail.To="[email protected]"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两仪 2024-08-20 05:35:01

我从来没有让 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;
    }
}

I never got the CDO.Message object to work on Windows Server 2008. However, I found a workaround. I wrote an email class that works on Windows Server 2008. Hope this helps someone else.

[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;
    }
}
酒儿 2024-08-20 05:35:01

只要您使用 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

As long as you're using the Microsoft SMTP server(1) you can use the IIS Metabase Explorer to give the IIS_USRS group(2) read read access to the /LM/SmtpSvc/ and /LM/SmtpSvc/1/ nodes in the IIS Metabase.

Unfortunately this solution doesn't apply to Windows 7. Microsoft does not ship an SMTP server with Windows 7, making it very difficult to get around this problem without refactoring your code.

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

(2) See 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文