c# ASP.NET 邮件发送

publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve... public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SendMail(this.TextBox1.Text,this.TextBox2.Text,this.TextBox3.Text,this.FCKeditor1.Value,new ArrayList());
}
catch(Exception er)
{
throw new Exception("发送失败!!!",er);
}

}

private void SendMail(string FromEmako, string ToEmail, string Title, string Body, ArrayList aFileName)
{
MailMessage mymail = new MailMessage();
StringBuilder MailBody = new StringBuilder();
mymail.From = "<" + FromEmako + ">" + FromEmako;
mymail.To = ToEmail;
mymail.Subject = Title;
mymail.BodyFormat = MailFormat.Html;

MailBody.Append("<style>A:visited{TEXT-DECORATION:none}");
MailBody.Append("A:active {TEXT-DECORATION:none}");
MailBody.Append("A:hover {TEXT-DECORATION:underline}");
MailBody.Append("A:link {taxt-decoration:none}");
MailBody.Append("A:visited {taxt-decoration:none}");
MailBody.Append("BODY {FONT-FAMILY:Verdana,宋体;FONT-SIZE;9pt;}");
MailBody.Append("TD {FONT-FAMILY:Verdana,宋体;FONT-SIZE;9pt;}</style>");
MailBody.Append("<TABLE border=0 width='95%' align=center><TBODY><TR>");
MailBody.Append("<TD valign=middle align=top>");
MailBody.Append("</TD></TR>");
MailBody.Append("</TBODY></TABLE><br>");
mymail.Body = MailBody.ToString();
for (int i = 0; i < aFileName.Count; i++)
{
MailAttachment mailA = new MailAttachment(aFileName[i].ToString());
mymail.Attachments.Add(mailA);
}
SmtpMail.Send(mymail);

}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.FCKeditor1.Value = null;
Response.Write("你已经取消发送邮件!!!");
}
}

这是我比这书上敲的
发送邮件的程序,主要就是 mymail.Body = MailBody.ToString();
for (int i = 0; i < aFileName.Count; i++)
{
MailAttachment mailA = new MailAttachment(aFileName[i].ToString());
mymail.Attachments.Add(mailA);
}
SmtpMail.Send(mymail);
这一点不明白,请将一下,
还有书上说还要配置发送电子邮件的服务器之后才能发送,我没有接触过,请问在哪找这个服务器呀,如何配置!请把这一点详细的给我说说!急用,谢谢了!我没有积分了,不好意思呀!
展开
 我来答
百度网友e27d6e6e3
2010-08-17 · TA获得超过605个赞
知道小有建树答主
回答量:361
采纳率:0%
帮助的人:0
展开全部
给你一个例子
public static void Send()
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = false;
client.Host = "smtp.163.com"; //可以配置成其他邮件服务器
client.Port = 25;
client.Credentials = new NetworkCredential("发件人邮件帐号", "邮箱密码");
MailMessage mm = new MailMessage();
mm.Priority = MailPriority.High;
mm.From = new MailAddress("发件人邮件帐号");
mm.Sender = new MailAddress("发件人邮件帐号");
mm.To.Add(new MailAddress("收件人邮件帐号"));
mm.Subject = "到期提醒!";
StringBuilder sb = new StringBuilder();
sb.AppendLine("到期提醒!");
sb.AppendLine("请登录人力资源系统及时处理即将到期的合同");
sb.AppendLine(DateTime.Now.ToShortDateString());
sb.AppendLine("人力资源系统管理员");
mm.Body = sb.ToString();
mm.IsBodyHtml = true;
// client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mm);
}
catch (Exception ex)
{
throw ex;
}
}
今天你去哪
2010-08-17 · TA获得超过604个赞
知道小有建树答主
回答量:513
采纳率:0%
帮助的人:253万
展开全部
添加删除程序中,试看添加smtp服务并配置它。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式