总结13发送email.docx
总结13发送emailEmail发送代码 1. C#代码发送类 using System; using System.Data; using System.Configuration; 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.Net.Mail; using System.Web.Configuration; using System.Collections.Generic; namespace WBIS.Base.Fun / <summary> / funSentEmail 的摘要描述 / </summary> public class funSentEmail public static string Error; / <summary> / / </summary> / <param name="FromEmail">发送人</param> / <param name="ToEmail">接收人</param> / <param name="Subject">主题</param> / <param name="Body">内容</param> / <param name="host">主机或服务器</param> / <param name="port">端口</param> / <returns></returns> public static bool SendEmail(string ToEmail, string Subject, string Body) bool Success = false; try string FromEmail = Constant.strEmaiFrom; string host = Constant.strMailserver; int port = Constant.intPort; System.Net.Mail.SmtpClient client; if (port != 0) client = new SmtpClient(host, port); else client = new SmtpClient(host); /client.Credentials = new System.Net.NetworkCredential("Ki", "123456"); /string inceptMail = WebConfigurationManager.AppSettings"ek_InceptMail".ToString; /MailMessage message = new MailMessage; /message.Bcc.Add(inceptMail); /message.From = new MailAddress(FromEmail); /message.To.Add(ToEmail); MailAddress from = new MailAddress(FromEmail); MailAddress to = new MailAddress(ToEmail); MailMessage message = new MailMessage(from, to); message.Subject = Subject; message.Body = Body; message.IsBodyHtml = true; client.Send(message); Success = true; catch (Exception ex) Error = ex.Message; Success = false; return Success; / <summary> / 发送email / </summary> / <param name="FromEmail">发送人</param> / <param name="ToEmail">接收人</param> / <param name="Subject">主题</param> / <param name="Body">内容</param> / <param name="host">主机或服务器</param> / <param name="port">端口</param> / <param name="strFiler">附件的地址</param> / <returns></returns> public static bool SendEmail(string ToEmail, string Subject, string Body, string strFiler) bool Success = false; if (!System.IO.File.Exists(strFiler) return false; try string FromEmail = Constant.strEmaiFrom; string host = Constant.strMailserver; int port = Constant.intPort; System.Net.Mail.SmtpClient client; if (port != 0) client = new SmtpClient(host, port); else client = new SmtpClient(host); MailAddress from = new MailAddress(FromEmail); MailAddress to = new MailAddress(ToEmail); MailMessage message = new MailMessage(from, to); message.Subject = Subject; message.Body = Body; message.IsBodyHtml = true; Attachment data = new Attachment(strFiler); message.Attachments.Add(data); client.Send(message); Success = true; catch (Exception ex) Error = ex.Message; Success = false; return Success; 2. asp代码通过JMAIL进行发送 如果服务器没有注册jmail,需要注册jmail:将jamil.dll组件复制到系统所在的磁盘的system32活页夹下,然后执行“开始”->“运行”命令,在弹出的“运行”对话框中输入regsvr32 jmail.dll <% On Error Resume Next 象 if err then err.clear Response.Write("组件检测失败!") jmail.close Set jmail=nothing Set jmail = Server.CreateObject("JMAIL.SMTPMail") '建立JMAIL对else jmail.logging = true '使用日志 jmail.Charset = "big5" '字体 jmail.ContentType = "text/html" '文件的格式 jmail.ServerAddress = strServer '发送的服务器 jmail.AddRecipient strTo '收件人 jmail.SenderName = " " '收件的姓名 jmail.Sender = strFrom '发送的邮件 jmail.Priority = 1 '1 最快,5 最慢, 3 默认 jmail.Subject = "Mail Subject" '主题 jmail.Body = "Mail Body" '内容 'jmail.AddRecipientBCC strServerUN '密件收件人的地址 'jmail.AddRecipientCC strServerPW '邮件件抄送者的地址 jmail.Execute '执行发送 jmail.Close '关闭对象 Set jmail=nothing if err then response.Write Err.Description err.clear %> end if end if 3. asp上传控件的使用 如果服务器没有注册AspUpload上传组件,需要注册AspUpload:安装aspupload.exe,安装完成后,在安装路径下找AspUploadBin把AspUpload.dll复制到系统所在的磁盘的system32活页夹下,然后执行“开始”->“运行”命令,在弹出的“运行”对话框中输入regsvr32 AspUpload.dll 需要设定form提交的属性 ENCTYPE="multipart/form-data" 如:<form action="maintain_meteor_up.asp" ENCTYPE="multipart/form-data" name="form1" method="post" onsubmit="return checkform;"> maintain_meteor_up.asp页面是进行上传的动作 在maintain_meteor_up.asp页的主要代码: Set Upload = Server.CreateObject("Persits.Upload.1") Upload.SetMaxSize 50000, False Upload.OverwriteFiles = True Upload.Save(server.mappath("images") filename=Upload.Files("meteo_Flash").filename usid=trim(Upload.form("sch0").value) sno=trim(Upload.form("sno").value) on error resume next