我在域中,每个人都用自己的帐号登陆,smtp server是域的,可以用自己的帐号验证。现在就是想实现不用输密码可以发信
红色句在winform中可用, debug时 也行  发布到IIS就不行了
IIS配置: 关闭匿名用户,集成windows身份验证
 public static void SendMail(string mFrom,string mTo, string mCC, string mSubject, string mBody)
    {
        MailAddress maFrom = new MailAddress(mFrom);
        MailAddress maTo = new MailAddress(mTo);
        MailMessage mm = new MailMessage(maFrom, maTo);
        mm.Subject = mSubject;
        mm.Body = mBody;
        mm.CC.Add(mCC);
        mm.IsBodyHtml = true;        string mServer = "serverip";
        int port = 25;//可以不写
        SmtpClient sc = new SmtpClient(mServer,port);
        sc.UseDefaultCredentials = true;
        sc.Send(mm);
    }
web.config 加上<identity impersonate="true"/>

解决方案 »

  1.   

    错误提示是:smtp 验证失败
      

  2.   

    应该是没有取到Credentials ,输入密码后可以正确发送
      

  3.   

    验证失败应该是SMTP服务器或者密码有问题吧!
      

  4.   

    要实现的效果就是不输入密码,我们的机器都是登陆的域帐户,winform程序可以取到,但iis就不行了,应该是配置问题
      

  5.   

    <identity   impersonate= "true" username="username" password="password"/> 
      

  6.   

    我要实现的是在域中不用输密码发邮件,当然smtp是域的。下面是我想到的一些替代方案:1. use IIS virtual SMTP server to send mail instead of 域中的smtp服务器,but all the mails are in “Queue” fold in company ,it may be stop by domain policy.
        public static void SendMail1(string mFromName, string mTo, string mCC, string mSubject, string mBody)
        {
            string mFrom = "[email protected]";
            MailAddress maFrom = new MailAddress(mFrom, mFromName);//自己的服务器随便写
            MailAddress maTo = new MailAddress(mTo);
            MailMessage mm = new MailMessage(maFrom, maTo);
            mm.Subject = mSubject;
            mm.Body = mBody;
            mm.CC.Add(mCC);
            mm.IsBodyHtml = true;        string mServer = "localhost";
            int port = 25;
            SmtpClient sc = new SmtpClient(mServer,port);
            sc.UseDefaultCredentials = true;
            sc.Send(mm);
     }
    2. Counterplans 1 ‘s code. It send mail succeed but displayName method cannot work .it also stop by domain policy. 
        public static void SendMail(string mFromName,string mTo, string mCC, string mSubject, string mBody)
        {
            string mFrom = "[email protected]";
            MailAddress maFrom = new MailAddress(mFrom, mFromName);- stop by domain policy.
            MailAddress maTo = new MailAddress(mTo);
            MailMessage mm = new MailMessage(maFrom, maTo);
            mm.Subject = mSubject;
            mm.Body = mBody;
            mm.CC.Add(mCC);
            mm.IsBodyHtml = true;        string mServer = "smtphost.redmond.corp.microsoft.com";
            SmtpClient sc = new SmtpClient(mServer);
            //sc.UseDefaultCredentials = true;//仅对winform有效,webform测试通过,但无法使用IIS(可模拟帐户)
            string pwd = MD5Decrypt(xmlGetValue("md5key"), xmlGetValue("md5"));
            sc.Credentials = new System.Net.NetworkCredential("dtest", pwd, "fareast");
            sc.Send(mm);
     }
    3. Simulate account: simply method is add this code to web.config <identity impersonate="true"  userName="fareast\dtest" password="" />
    //这种方法只能模拟一个,实际用的时候是以编程方式模拟的,需要调用很多系统dll文件,很麻烦
    http://blog.csdn.net/webwalker/archive/2007/05/21/1618711.aspx
      

  7.   

    MailMessage m = new MailMessage();
    m.From = strFrom;
    m.To = strTo;
    m.Subject = strSubject;
    m.Body = strBody;
    m.BodyFormat = MailFormat.Html;
    SmtpMail.SmtpServer = strSMTPServer;
    m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
    "1");//basic authentication
    m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
    strFrom); //set your username here
    m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
    strPass);//set your password here
    try
    {SmtpMail.Send(m);}
    catch (System.Exception e)
    {
    return e.Message;
    }