文件名称:邮件发送的源码
文件大小:21KB
文件格式:RAR
更新时间:2015-08-16 07:30:49
发送邮件源码
protected string ServerAddress;//服务器地址 protected string TheSender;//发件人 protected string Password;//密码 protected string TheRecipient;//收件人 protected string Theme;//主题 protected string Content;//发生的内容 bool result = false; public void ProcessRequest(HttpContext context) { ServerAddress = context.Request.Form["ServerAddress"]; TheSender = context.Request.Form["TheSender"]; Password = context.Request.Form["Password"]; TheRecipient = context.Request.Form["TheRecipient"]; Theme = context.Request.Form["Theme"]; Content = context.Request.Form["Content"]; SendSmtpMail(TheRecipient); if (result == true) { context.Response.Write("[removed]alert('发生成功!')[removed]"); context.Response.Write("[removed]location.href='EmailOut.aspx'[removed]"); } else { context.Response.Write("[removed]alert('发送失败!'[removed])"); context.Response.Write("[removed]location.href='EmailOut.aspx'[removed]"); } } public bool SendSmtpMail(string emailAddress) { //emailAddress(收件人的邮箱) string strSmtpServer = ServerAddress;//(用的是163的邮箱,如果要用其他邮箱自己改)服务器 string strFrom = TheSender;//本人的邮箱账号(发送邮件的邮箱账号) string strFromPass = Password;//本人的邮箱密码(发送邮件的邮箱密码) SmtpClient client = new SmtpClient(strSmtpServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage message = new MailMessage(); message.From = new MailAddress(strFrom); message.To.Add(emailAddress);//获取收件人地址集合 message.Subject = Theme;//邮箱主题 message.Body = Content;//内容 message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; try { client.Send(message); result = true; } catch (Exception) { } return result; }
【文件预览】:
EmailOut
----EmailOut()
--------bin()
--------EmailOut.csproj.user(1KB)
--------Web.config(313B)
--------obj()
--------Web.Debug.config(1KB)
--------EmailOut.ashx.cs(3KB)
--------EmailOut.aspx(2KB)
--------Web.Release.config(1KB)
--------EmailOut.aspx.designer.cs(804B)
--------EmailOut.ashx(96B)
--------EmailOut.csproj(4KB)
--------EmailOut.aspx.cs(330B)
--------Properties()
----EmailOut.suo(11KB)
----EmailOut.sln(914B)