简体   繁体   English

Exchange 2003与C#smtpclient

[英]Exchange 2003 with C# smtpclient

I am currently trying to use SmtpClient to send an email with exchange 2003. Using the code below it will not send an email, but it does not throw an exception which i assume means it is making a connection to the exchange server because. 我目前正在尝试使用SmtpClient向Exchange 2003发送电子邮件。使用下面的代码它不会发送电子邮件,但它不会抛出异常,我认为这意味着它正在与Exchange服务器建立连接,因为。 Also for the server setting I tried mail.server.com as well as the IP address and it still does not throw an exception. 另外对于服务器设置我尝试了mail.server.com以及IP地址,它仍然没有抛出异常。

        public static void emailTest()
    {
        string fromEmail = @"me@me.com";
        string ToEmail = @"me@me.com";          
        string body = "C Stuck Batches"; 
        string subject = "C Stuck Batches"; 

        try
        {
            SmtpClient MyMail = new SmtpClient("x.x.x.x");
            MyMail.DeliveryMethod = SmtpDeliveryMethod.Network;
            MyMail.UseDefaultCredentials = false;
            MyMail.Credentials = new NetworkCredential(@"domain\user", "password"); 

            MyMail.Send(fromEmail, ToEmail, subject, body);
            MessageBox.Show("Sent", "SENT", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Exception", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        } 
    }

I have read through several other problems, but as far as I could tell most others were getting some sort of exception or timeout. 我已经阅读了其他几个问题,但据我所知,其他大多数人都遇到了某种异常或超时。 Since this appears as though it connects I am not sure what the issue is. 由于这似乎连接,我不知道是什么问题。 Would it throw an exception if it were unable to access the server? 如果它无法访问服务器,它会抛出异常吗? If I throw a different IP into the server it will throw an exception. 如果我将不同的IP扔进服务器,它将抛出异常。

Also I have tried both the IP of the server and mail.xx.com and it will not throw an exception with either but if I put any other addresses it will fail. 此外,我已经尝试了服务器的IP和mail.xx.com,它不会抛出异常,但如果我放任何其他地址,它将失败。

Thanks in advance for anyhelp! 在此先感谢任何帮助!

Is your Exchange server set up to relay mail from your IP address? 您的Exchange服务器是否设置为从您的IP地址中继邮件? If it isn't, mail may be "silently" discarded without throwing an Exception (the client is connecting correctly, it's the back end that's discarding the email) 如果不是,可以“静默”丢弃邮件而不抛出异常(客户端正确连接,它是丢弃电子邮件的后端)

This link provides more information on how to configure relaying on Exchange 2003 (I'm assuming "eSupport" would equate to your application in this example ie the IP of the machine running your code). 此链接提供了有关如何在Exchange 2003上配置中继的更多信息(我假设“eSupport”等同于此示例中的应用程序,即运行代码的计算机的IP)。

Log into Exchange 2003 server (192.168.5.25 in my example above) and start Exchange System Manager. 登录到Exchange 2003服务器(在上面的示例中为192.168.5.25)并启动Exchange系统管理器。

Expand the organization_name object, and then expand the Servers node. 展开organization_name对象,然后展开“服务器”节点。 Expand the server_name object of the server on which you want to control mail relay, and then expand the Protocols node. 展开要控制邮件中继的服务器的server_name对象,然后展开“协议”节点。

Expand the SMTP node, right-click the virtual SMTP server on which you want to control mail relay, and then click Properties 展开SMTP节点,右键单击要控制邮件中继的虚拟SMTP服务器,然后单击“属性”

Click Relay. 单击“中继”。

In the Relay Restriction dialog box, several options are available. 在“中继限制”对话框中,有几个选项可用。 The Only the list below option is enabled by default; 默认情况下,仅启用以下列表选项; the list below this option is empty. 此选项下方的列表为空。

Click Add. 单击添加。 Enter the IP address of the server running eSupport (192.168.5.80 in my example above). 输入运行eSupport的服务器的IP地址(在上面的示例中为192.168.5.80)。

In the Relay Restrictions dialog box, click OK. 在“中继限制”对话框中,单击“确定”。

Click Apply, and then click OK in the Default SMTP Virtual Server Properties dialog box. 单击“应用”,然后在“默认SMTP虚拟服务器属性”对话框中单击“确定”。

The issues i had was that even the domain admins did not have access to the SMTP relay. 我遇到的问题是即使域管理员也无法访问SMTP中继。 I had to make sure the user was authenticated in the SMTP relay. 我必须确保用户在SMTP中继中进行了身份验证。 Regardless of the fact the authenicating user was the same as the email adress used, that user did not have access. 无论验证用户与使用的电子邮件地址相同,该用户都无权访问。 Once corrected it was able to send without issue. 一旦纠正,它就可以毫无问题地发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM