公司的网络使通过代理访问Internet的,并且设置代理服务器后,还需要进行身份认证,譬如我的用户名是sysuser密码是123456,输入用户名密码后,才能上网。我现在要用程序来发送邮件,使用的是CDO,不过好像发不出去。大家帮忙看一下,主要是怎么来验证我的身份。然后上网。       private void button1_Click(object sender, EventArgs e)
        {            try
            {
                System.Web.Mail.MailMessage em = new System.Web.Mail.MailMessage();                em.BodyFormat = MailFormat.Html;
                em.To = "[email protected]"; //收件人
                em.From = "[email protected]";  //发件人
                em.Subject = "dd";                em.Body = "dddd"; // 发送的信件内容
                //Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)
                //系统校验
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");   //basic authentication
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxyserver", "182.1.1.200");
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/proxyserverport", 80);
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "test"); //set your username here
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "test2008"); //set your password here
                em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout",5);   //下边这两个不是这么使用的,是我瞎写的。大家看看有什么需要设置的。
                //em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpaccountname", "sysuser");
                //em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxybypass","123456");
                //   Set   Proxy   properties   
                SmtpMail.SmtpServer = "smtp.126.com";
                SmtpMail.Send(em);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
大家帮忙看一下了,如果有做过通过代理服务器发送邮件的可以联系我,MSN:[email protected]
在线等待!!!

解决方案 »

  1.   

    希望大家能帮忙看一下,多谢了!!!MSN:[email protected] 在线等待!!!
      

  2.   

     Public Function SendMail()
            Try
                Dim mail As New MailMessage
                mail.From = "<" + FromAddr + ">" + FromName
                mail.To = toAddress
                mail.Cc = CcAddress
                mail.Bcc = BccAddress
                mail.Subject = Subject
                mail.Body = CreateBody(Body, New String() {strCallerBasyoID})            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true") //如果有SSL认证的话就要这句
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName)
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord)
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Integer.Parse(smtpport))  //端口            System.Web.Mail.SmtpMail.SmtpServer = SearverIp
                System.Web.Mail.SmtpMail.Send(mail)        Catch ex As Exception
                HCLogger.WriteLog(HCLogger.LogLevel.ERR, "HCSendMail の SendMail()関数にエラーがある")
                Dim strFormBase As HCFormBase = HCFormBase.GetForm("HCErrorMessageForm")            If Not strFormBase Is Nothing Then
                    strFormBase.CallingNotice(Nothing, Nothing, errorMessage)
                End If
            End Try
        End Function这是我们项目里用的VB的代码,不过一样的都是,你看看是不是可以,我们公司也要通过代理上网的还有建议搂住先通过设置outlook看看能不能收发邮件,如果连outlook都收发不了那用程序发肯定是不行的,这个问题我做项目的时候也遇到过
      

  3.   

    参考以下代码
                try
                {
                   MailMessage mm = new MailMessage("######@163.com", tbmailTo.Text.Trim(), tbmailSubject.Text, sendMessage.Text);
                    sc = new SmtpClient("smtp.163.com", 25);
                    sc.Credentials = new NetworkCredential("用户名", "密码");//设置用户发送邮件的凭据                Thread send = new Thread(new ThreadStart(send_Mail));
                    send.Start();
                    sendStatus.Text = "请稍后,正在发送邮件...";
                    this.Send.Enabled = false;
                }
                catch//(Exception exp)
                {
                    //MessageBox.Show(exp.Message);
                    MessageBox.Show("请检查收件人地址是否正确!");
                }
      

  4.   

    我用foxmail是可以接收的,我测试了你的代码,我的还是不能发送,不过谢谢了!!
      

  5.   

    好像只要设置发送邮件的代理服务器就可以了
    比如 网易
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",   UserName) 
                            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",   PassWord) 这里要的用户名和密码是网易账号和密码
      

  6.   

    发送邮件的环境的前提是,你的网络无阻。
    然后你去网易申请一个通行证,开始邮件。
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",       UserName)   
                                                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",       PassWord)   这里的用户名和密码,就是你的在网易申请的通行证和密码。如果不行,我也不知道了。如果问题解决了,也请你告诉我
    谢谢