实现asp.net(c#)用户注册之后自动发送email到用户邮箱。 我网站想实现一个,用户注册后自动回复用户一邮件进行确认。!~但是由于是菜鸟,在网上面收了很多类似system.web.mail的一些代码,我自己有点儿看不懂,所以希望大家给我解说一下。希望贴代码+注释最好了。我在这里感谢大家了。如果方便,我把QQ留下804172665如果有心的加我哦。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Web.Util;using System.Web.Mail;/// <summary>///SendMail 的摘要说明/// </summary>public class SendMail{ public SendMail() { // //TODO: 在此处添加构造函数逻辑 // } /// <summary> ///SendMail 的摘要说明 /// </summary> /// <param name="fromMail">发件人</param> /// <param name="toMail">收件人</param> /// <param name="ccMail">抄送人</param> /// <param name="bccMail">暗送人</param> /// <param name="subject">主题</param> /// <param name="body">内容</param> /// <param name="sendMode">模式</param> /// <returns>查询结果(bool)是否成功</returns> public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode) { try { MailMessage myMail = new MailMessage(); myMail.From = "[email protected]";// fromMail;//发件人 myMail.To = fromMail;//收件人 myMail.Cc = ccMail;//抄送人 myMail.Bcc = bccMail;//暗送人 myMail.Subject = subject;//主题 myMail.Body = body; myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html; //附件 //string ServerFileName = ""; //if (this.upfile.PostedFile.ContentLength != 0) //{ // string upFileName = this.upfile.PostedFile.FileName; // string[] strTemp = upFileName.Split('.'); // string upFileExp = strTemp[strTemp.Length - 1].ToString(); // ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp); // this.upfile.PostedFile.SaveAs(ServerFileName); // myMail.Attachments.Add(new MailAttachment(ServerFileName)); //} myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户 myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码 SmtpMail.SmtpServer = "smtp.126.com"; SmtpMail.Send(myMail); return true; } catch { return false; } }} using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Net.Mail;namespace WindowsFormsApp_csMailSend{ public static class Mail { public static bool SendMail(string FromMail,string PassWord,string SmtpServer,string ToMail,string Subject,string Body,string AddFile) { try { SmtpClient objSmtpClient = new SmtpClient();//("[email protected]",25 objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; objSmtpClient.Host = SmtpServer; objSmtpClient.Credentials = new NetworkCredential(FromMail.Split('@').GetValue(0).ToString(), PassWord); MailMessage objMail = new MailMessage(FromMail,ToMail); objMail.Body = Body; objMail.Subject = Subject; if (AddFile != "") { Attachment objAttachment = new Attachment(AddFile); objMail.Attachments.Add(objAttachment); } objSmtpClient.Send(objMail); return true; } catch { return false; } } }} private void btSend_Click(object sender, EventArgs e) { if (Mail.SendMail(tbFromMail.Text, tbpassword.Text, tbSmtpServer.Text, tbToMail.Text, tbobj.Text, tbbody.Text, tbAddFile.Text)) { MessageBox.Show("邮件发送成功!", "系统提示", MessageBoxButtons.OK,MessageBoxIcon.Information); } else { MessageBox.Show("邮件发送失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Util; using System.Web.Mail; /// <summary> ///SendMail 的摘要说明 /// </summary> public class SendMail { public SendMail() { // //TODO: 在此处添加构造函数逻辑 // } /// <summary> ///SendMail 的摘要说明 /// </summary> /// <param name="fromMail">发件人 </param> /// <param name="toMail">收件人 </param> /// <param name="ccMail">抄送人 </param> /// <param name="bccMail">暗送人 </param> /// <param name="subject">主题 </param> /// <param name="body">内容 </param> /// <param name="sendMode">模式 </param> /// <returns>查询结果(bool)是否成功 </returns> public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode) { try { MailMessage myMail = new MailMessage(); myMail.From = "[email protected]";// fromMail;//发件人 myMail.To = fromMail;//收件人 myMail.Cc = ccMail;//抄送人 myMail.Bcc = bccMail;//暗送人 myMail.Subject = subject;//主题 myMail.Body = body; myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html; //附件 //string ServerFileName = ""; //if (this.upfile.PostedFile.ContentLength != 0) //{ // string upFileName = this.upfile.PostedFile.FileName; // string[] strTemp = upFileName.Split('.'); // string upFileExp = strTemp[strTemp.Length - 1].ToString(); // ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp); // this.upfile.PostedFile.SaveAs(ServerFileName); // myMail.Attachments.Add(new MailAttachment(ServerFileName)); //} myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户 myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码 SmtpMail.SmtpServer = "smtp.126.com"; SmtpMail.Send(myMail); return true; } catch { return false; } } 昨天我刚刚做过,呵呵,不能的啊,你给他发送的url就是连接到你的修改密码的页面上的,有什么难度的?上面的回复已经可以发邮件了,你只要邮件就可以了,然后在修改密码的页面上判断一下是不是从连接进来的,然后处理修改密码。 让邮件的主体以html形式各显不可以了吗?根据不同的要求可以设置不同 的邮件主题.... js和html问题 大家帮忙看一下这个语句正确吗? 将页面的隐藏数据导入到excel表中 新手求助 请问一个获取存储过程返回值的问题 !! 如何自定义 dropdownlist 滚动条长度 ?? c#怎样在限定时间完成某时间? asp.net(数据库是SQL)如何调用EXCEL作图返回到网页中? 还是复合控件的问题:关于设置控件属性的默认值的问题,高手请进! 请问这中tabcontrol + navbargroup这种便签样式怎么实现 存储过程中的这句是啥意思? 在FIREFOX退出系统后,返回前页还是进到系统原来的页面。
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Util;
using System.Web.Mail;
/// <summary>
///SendMail 的摘要说明
/// </summary>public class SendMail
{
public SendMail()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
///SendMail 的摘要说明
/// </summary>
/// <param name="fromMail">发件人</param>
/// <param name="toMail">收件人</param>
/// <param name="ccMail">抄送人</param>
/// <param name="bccMail">暗送人</param>
/// <param name="subject">主题</param>
/// <param name="body">内容</param>
/// <param name="sendMode">模式</param>
/// <returns>查询结果(bool)是否成功</returns>
public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
{
try
{
MailMessage myMail = new MailMessage();
myMail.From = "[email protected]";// fromMail;//发件人
myMail.To = fromMail;//收件人
myMail.Cc = ccMail;//抄送人
myMail.Bcc = bccMail;//暗送人
myMail.Subject = subject;//主题
myMail.Body = body;
myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;
//附件
//string ServerFileName = "";
//if (this.upfile.PostedFile.ContentLength != 0)
//{
// string upFileName = this.upfile.PostedFile.FileName;
// string[] strTemp = upFileName.Split('.');
// string upFileExp = strTemp[strTemp.Length - 1].ToString();
// ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
// this.upfile.PostedFile.SaveAs(ServerFileName);
// myMail.Attachments.Add(new MailAttachment(ServerFileName));
//}
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码
SmtpMail.SmtpServer = "smtp.126.com";
SmtpMail.Send(myMail);
return true;
}
catch
{
return false;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;namespace WindowsFormsApp_csMailSend
{
public static class Mail
{
public static bool SendMail(string FromMail,string PassWord,string SmtpServer,string ToMail,string Subject,string Body,string AddFile)
{
try
{
SmtpClient objSmtpClient = new SmtpClient();//("[email protected]",25
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Host = SmtpServer;
objSmtpClient.Credentials = new NetworkCredential(FromMail.Split('@').GetValue(0).ToString(), PassWord); MailMessage objMail = new MailMessage(FromMail,ToMail);
objMail.Body = Body;
objMail.Subject = Subject; if (AddFile != "")
{
Attachment objAttachment = new Attachment(AddFile);
objMail.Attachments.Add(objAttachment);
} objSmtpClient.Send(objMail); return true;
}
catch
{
return false;
}
}
}
}
{
if (Mail.SendMail(tbFromMail.Text, tbpassword.Text, tbSmtpServer.Text, tbToMail.Text, tbobj.Text, tbbody.Text, tbAddFile.Text))
{
MessageBox.Show("邮件发送成功!", "系统提示", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("邮件发送失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Util;
using System.Web.Mail;
/// <summary>
///SendMail 的摘要说明
/// </summary> public class SendMail
{
public SendMail()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
///SendMail 的摘要说明
/// </summary>
/// <param name="fromMail">发件人 </param>
/// <param name="toMail">收件人 </param>
/// <param name="ccMail">抄送人 </param>
/// <param name="bccMail">暗送人 </param>
/// <param name="subject">主题 </param>
/// <param name="body">内容 </param>
/// <param name="sendMode">模式 </param>
/// <returns>查询结果(bool)是否成功 </returns>
public bool WriteAndSendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
{
try
{
MailMessage myMail = new MailMessage();
myMail.From = "[email protected]";// fromMail;//发件人
myMail.To = fromMail;//收件人
myMail.Cc = ccMail;//抄送人
myMail.Bcc = bccMail;//暗送人
myMail.Subject = subject;//主题
myMail.Body = body;
myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;
//附件
//string ServerFileName = "";
//if (this.upfile.PostedFile.ContentLength != 0)
//{
// string upFileName = this.upfile.PostedFile.FileName;
// string[] strTemp = upFileName.Split('.');
// string upFileExp = strTemp[strTemp.Length - 1].ToString();
// ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
// this.upfile.PostedFile.SaveAs(ServerFileName);
// myMail.Attachments.Add(new MailAttachment(ServerFileName));
//}
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sunshijie110"); //发送方邮件帐户
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "****"); //发送方邮件密码
SmtpMail.SmtpServer = "smtp.126.com";
SmtpMail.Send(myMail);
return true;
}
catch
{
return false;
}
}