总结_13发送email_第1页
总结_13发送email_第2页
总结_13发送email_第3页
总结_13发送email_第4页
总结_13发送email_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Email发送代码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;u

2、sing 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&qu

3、ot;>接收人</param> / <param name="Subject">主题</param> / <param name="Body">内容</param> / <param name="host">主机或服务器</param> / <param name="port">端口</param> / <returns></returns> public static bool

4、 SendEmail(string ToEmail, string Subject, string Body) bool Success = false; try string FromEmail = Constant.strEmaiFrom; string host = Constant.strMailserver; int port = CPort; System.Net.Mail.SmtpClient client; if (port != 0) client = new SmtpClient(host, port); else client = new SmtpC

5、lient(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 MailAddre

6、ss(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 (

7、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

8、 name="Body">内容</param> / <param name="host">主机或服务器</param> / <param name="port">端口</param> / <param name="strFiler">附件的地址</param> / <returns></returns> public static bool SendEmail(string ToEmail, strin

9、g 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 = CPort; System.Net.Mail.SmtpClient client; if (port != 0) client = new SmtpClient(

10、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(strF

11、iler); 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活页夹下(如:c:winntsystem32),然后执行“开始”->“运行”命令,在弹出的“运行”对话框中输入regsvr32 jmail.dl

12、l<%On Error Resume Next Set jmail = Server.CreateObject("JMAIL.SMTPMail") '建立JMAIL对象if err then err.clear Response.Write("组件检测失败!") jmail.close() Set jmail=nothingelse jmail.logging = true '使用日志 jmail.Charset = "big5" '字体 jmail.ContentType = "text/ht

13、ml" '文件的格式 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"

14、'内容 'jmail.AddRecipientBCC strServerUN '密件收件人的地址 'jmail.AddRecipientCC strServerPW '邮件件抄送者的地址 jmail.Execute() '执行发送 jmail.Close '关闭对象Set jmail=nothingif err thenresponse.Write Err.Descriptionerr.clearend if end if%>3. asp上传控件的使用如果服务器没有注册AspUpload上传组件,需要注册AspUpload:安装as

15、pupload.exe,安装完成后,在安装路径下找AspUploadBin把AspUpload.dll复制到系统所在的磁盘的system32活页夹下(如:c:winntsystem32),然后执行“开始”->“运行”命令,在弹出的“运行”对话框中输入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 50

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论