email.SendAndSaveCopy();陷入困境 [英] email.SendAndSaveCopy(); stuck problem

查看:415
本文介绍了email.SendAndSaveCopy();陷入困境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i我通过交换服务器版本Exchange2010发送邮件。



以下是我的代码:



hi all,

i am sending mail through exchange server version Exchange2010.

below is my code:

static void Main()
        {
            try
            {
                string owausername = string.Empty;
                string owapassword = string.Empty;
                string mailFrom;
                string mailTo;
                string mailSub;
                string mailBody;

                ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
                EmailMessage email = new EmailMessage(service);

                string reg_subKey = "Software\\VB and VBA Program Settings\\LangServ15.2";
                RegistryKey root = Registry.CurrentUser.CreateSubKey(reg_subKey);
                foreach (string keyname in root.GetSubKeyNames())
                {
                    using (RegistryKey key = root.OpenSubKey(keyname, true))
                    {
                        foreach (string valueName in key.GetValueNames())
                        {

                            if (valueName == "owausername")
                            {
                                if (key.GetValue(valueName).ToString() != "")
                                {
                                    owausername = key.GetValue(valueName).ToString();
                                }
                            }
                            if (valueName == "owapassword")
                            {
                                if (key.GetValue(valueName).ToString() != "")
                                {
                                    owapassword = key.GetValue(valueName).ToString();
                                }
                            }
                            service.Credentials = new WebCredentials(owausername, owapassword);
                            if (valueName == "owaurl")
                            {
                                if (key.GetValue(valueName).ToString() != "")
                                {
                                    service.Url = new Uri(key.GetValue(valueName).ToString());
                                }
                            }
                            if (valueName == "textFrom")
                            {
                                if (key.GetValue(valueName).ToString() != "")
                                {
                                    mailFrom = key.GetValue(valueName).ToString();
                                }
                            }
                            if (valueName == "textTo")
                            {
                                mailTo = key.GetValue(valueName).ToString();
                                email.ToRecipients.Add(mailTo);
                            }
                            if (valueName == "textSub")
                            {
                                mailSub = key.GetValue(valueName).ToString();
                                email.Subject = mailSub;
                            }
                            if (valueName == "textBody")
                            {
                                mailBody = key.GetValue(valueName).ToString();
                                email.Body = mailBody;

                            }
                        }
                        root.DeleteSubKey(keyname);
                    }
                }
                email.SendAndSaveCopy();
                System.Windows.Forms.MessageBox.Show("Email Sent Successfully...");
            }
            catch (Exception ex)
            {
                if (ex.Message.ToString() == "The request failed. The remote server returned an error: (401) Unauthorized.")
                {
                    System.Windows.Forms.MessageBox.Show("The OWA user name or OWA password you entered isn''t correct. Enter corrent credentials and then Try again.");
                }
                //throw ex;
            }
        }
        private static bool CertificateValidationCallBack(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }





我正在做什么我用这个代码编写.exe并从我的vb6.0应用程序调用。

它在我的本地机器上运行正常。但是当我将它上传到我的实时服务器上并测试它时。卡在一行



what i am doing i made .exe of this code and calling from my vb6.0 application.
it works fine on my local machine.but when i upload it on my live server and test it.it stucks at one line

email.SendAndSaveCopy();</pre>

。所有其他事情都很顺利。



帮助将不胜感激。



谢谢,

kk

. All other things are going fine.

help would be appreciated.

thanks,
kk

推荐答案

实际上在我上面的代码中我评论过
actually in my above code i commented
throw ex;

。所以我取消注释并写下面的代码来引发错误。

. so i uncomment it and wrote below code to raise error.

System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
throw ex;



我发现它抛出错误:



请求失败.unable连接到远程服务器。

实际上我的交换服务器没有在我的直播服务器上打开。我的服务器防火墙阻止了我的交换服务器。



谢谢,

kk


and i found it throws error :

the request failed.unable to connect to remote server.
actually my exchange server is not opening on my live server.my live server firewall blocked my exchange server.

thanks,
kk


这篇关于email.SendAndSaveCopy();陷入困境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆