我在域中,每个人都用自己的帐号登陆,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"/>
红色句在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"/>
解决方案 »
- 注册 HTTP 处理程序
- 请问如何将内容页的按钮注册到母板页中的UpdatePanel
- 急求Response.Write问题
- 关与.net2005引用DLL的问题
- 用户控件和窗体如何通信?
- A页面将post数据到B页面,B页面Response.Redirect到C页面,C页面通过Request接收不到A提交到的数据?如何解决,不用Session...
- 不能在C#中新建ASP的应用程序
- 输入的textbox用regularexpression控件来验证 *************出手从来100分*********************
- 可以提供一些有关VS.NET的教程吗?谢谢!
- 怎样隐藏自己的ip地址,使它不会被web服务器中的程序检测到,或是让他检测到一个假的
- asn.net 2.0 中global.asax文件的问题
- 问一个遭鄙视的问题,帮忙看看
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
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;
}