首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮小弟我写一个邮件发送事例

2012-01-14 
帮我写一个邮件发送事例发送人:wkjdf@sina.com密码:ksnsw接收人:mdnw6@sina.com密码:kd8ed只要能发送就行~

帮我写一个邮件发送事例
发送人:wkjdf@sina.com   密码:ksnsw
接收人:mdnw6@sina.com   密码:kd8ed

只要能发送就行~~
写一个简单的事例就行,网页打开就发送就行。我写了很多遍总是报错,所以希望大家帮忙。
我的是vs2003。写asp.net网页

[解决办法]
刚写的找回密码
楼主自己根据需求改改吧,你把写邮件者的配置写在web.config就可以


/// <summary>
/// 发送邮件
/// </summary>
/// <param name= "_UserName "> 用户名 </param>
/// <param name= "_Mail "> 用户注册的电子邮件 </param>
/// <param name= "_Pwd "> 用户登录密码 </param>
/// <returns> 是否发送成功 </returns>
public bool SendMail (string _UserName,string _Mail,string _Pwd)
{
string _adminMail = System.Configuration.ConfigurationSettings.AppSettings[ "AdminMail "].ToString();
string _adminMailPwd = System.Configuration.ConfigurationSettings.AppSettings[ "AdminMailPwd "].ToString();
string _adminMailSmtp = System.Configuration.ConfigurationSettings.AppSettings[ "AdminMailSMTP "].ToString();

MailMessage mailObj = new MailMessage();
mailObj.To = _Mail;
mailObj.From = _adminMail;

mailObj.Subject = "您的内网密码 ";
mailObj.Body = "尊敬的用户: <br/> &nbsp;&nbsp;&nbsp;&nbsp;您好,您的内网注册信息如下 <br/> 用户名: " + _UserName + " 密码: " + _Pwd;

mailObj.BodyFormat = MailFormat.Html;

mailObj.Priority = MailPriority.High;

SmtpMail.SmtpServer = _adminMailSmtp;
//mailObj.Attachments.Add(new MailAttachment( "c:\\swf\\000.bmp "));


string[] adminName = _adminMail.Split( '@ ');
///////////////////////////////////FrameWork1.1
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
////设置验证用户名
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", adminName[0].ToString());
////设置验证密码
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", _adminMailPwd);
//////////////////////////////////////////////

SmtpMail.Send(mailObj);
return true;
}
#endregion


web.config
<appSettings>
<add key= "ConnString " value= "server=192.168.10.19;uid=sa;pwd=123;DataBase=SDPriceWebSystem "/>
<add key= "AdminMail " value= "______@163.com "/>
<add key= "AdminMailPwd " value= "_____ "/>
<add key= "AdminMailSMTP " value= "Smtp.163.com "/>


</appSettings>



[解决办法]
MailMessage mm = new MailMessage();

mm.From= " ";
mm.To= " ";
mm.Subject = " " ;
mm.Body = " ";
// HTML格式
mm.BodyFormat=MailFormat.Html;
mm.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
mm.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", 邮件用户名);
mm.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ",密码 );
SmtpMail.SmtpServer = "mail.163.com ";---邮件服务器

SmtpMail.Send(mm);
这是2003的

[解决办法]
只要出现System.Web.Mail:
就是2005的
所以不适合你~~

热点排行