using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public bool SendNetMail(string mailFrom, string mailTo, string mailPassWord,
string Server_Address, int Server_port)
{
string mailSubject = "imyasgs";//主题
string mailBody = "imqsgsgs"; //内容
//创建邮件
//参数说明:
//mailFrom :发送邮件地址
//mailTo:接收邮件地址
//mailPassWord:发送邮件的邮箱密码
//mailSubject:邮件主题
//mailBody:邮件内容
//mailfilePath:邮件附件的路径集合,主要考虑到有时会发送多个附件的情况。
//Server_Address:Smtp服务器地址
//Server_port服务器端口
System.Net.Mail.MailMessage newMail = new System.Net.Mail.MailMessage(mailFrom, mailTo, mailSubject, mailBody);
newMail.IsBodyHtml = true;
newMail.Priority = System.Net.Mail.MailPriority.Normal;//邮件发送优先级高
//发送邮件
string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(mailSmtp[1].Insert(0, Server_Address),
Server_port);
client.Credentials = new System.Net.NetworkCredential(mailSmtp[0], mailPassWord);
try
{
client.Send(newMail);
return true;
}
catch
{
return false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
////读出数据库的发送邮件
//string fa;
//string mi;
////fff
//foreach(DataRow dr in )
//{
// bool 33= fdf
// if(bool)
// {
// }
//}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (SendNetMail("x@163.com", "y@163.com", "aaa123456", "SMTP.", 25))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "<script>alert('发送成功')</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "<script>alert('发送成功')</script>");
}
}
}