English 中文(简体)
CDO.Message giving "Access denied" on Windows Server 2008
原标题:

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="sender@mycompany.com"
    myMail.To="recipient@mycompany.com"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
End If
问题回答

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

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





相关问题
PHP fopen/fwrite problem on IIS7

I am running PHP5 on IIS7 on Windows Server 2008 R2. Check out the below code which writes a string received via a POST request parameter into an XML file. <?php $temp = ""; if($_SERVER[ ...

CDO.Message giving "Access denied" on Windows Server 2008

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 ...

Recreate DefaultWebsite on IIS7 / Windows Web Server 2008

I have accidently deleted the default-website on an "experimental" machine. It is a standard-installation of "Windows Web Server 2008" with II7 running. I have already tried to create a custom ...

how to create a web part to track page creation time

I am new to SharePoint Server 2007 Web Part, and I am using SharePoint Server 2007 on Windows Server 2008. I program using VSTS 2008 + C# + .Net 3.5. I want to create a simple web part which could ...

热门标签