如何在asp.net网站上实现电子邮件模块? [英] how to implement email module in asp.net web site ?

查看:114
本文介绍了如何在asp.net网站上实现电子邮件模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i希望在我的asp.net网站上实现电子邮件模块。

我希望收件箱,创建电子邮件,发送电子邮件,开箱草稿设施。

如何做到目前为止我已经完成了发送邮件的代码但没有实现完整的电子邮件帮助来做到这一点。

解决方案

实现模块



1.创建一个名为MyModule的新Visual Studio .NET C#类库项目。

2.设置对System.Web.dll程序集的引用。

3.将以下指令添加到类中:

 使用 System.Web; 



4.重命名类SyncModule.cs,然后更改类定义以反映这一点。

5.实现IHttpModule接口。您的班级定义应如下所示:

> public  class  SyncModule:IHttpModule 



6.按如下方式实现IHttpModule接口的Init和Dispose方法:

  public   void  Init(HttpApplication app)
{
app.BeginRequest + = EventHandler(OnBeginRequest);
}

public void Dispose(){}





7.创建活动的代表如下:

 public delegate void MyEventHandler (Object s,EventArgs e)



8.定义MyEventHandler类型的私有局部变量以保存对事件的引用:

 private MyEventHandler _eventHandler = null; 



9.创建一个事件,将委托连接到Global.asax文件或继承自的类的方法HttpApplication对象:

  public   event  MyEventHandler MyEvent 
{
add {_eventHandler + = value ; }
remove {_eventHandler - = value ; }
}



10.创建OnBeginRequest方法,该方法连接到HttpApplication的BeginRequest事件:

  public   void  OnBeginRequest( Object  s,EventArgs e)
{
HttpApplication app = s as HttpApplication;
app.Context.Response.Write(& quot; Hello 来自 OnBeginRequest 自定义模块&安培; LT峰; br&安培; GT;&安培; QUOT);
if (_ eventHandler!= null
_eventHandler( this null );
}



11.编译项目。



部署模块



1.在C:\ Inetpub \Wwwroot下创建一个名为Module的新目录。

2.创建一个名为的子目录Bin在新创建的Module目录中。结果路径为C:\Inetpub \Wwwroot \Module \ Bin。

3.将MyModule.dll从项目的Bin \Debug目录复制到C:\ Inetpub \ Wwwroot \Module \ Bin目录。

4.按照以下步骤将新模块目录标记为Web应用程序:

a。打开Internet服务管理器。

b。右键单击Module目录,然后单击Properties。

c。在目录选项卡上,单击创建。

d。单击确定关闭模块属性对话框。



配置系统



1.在C:\Inetpub \Wwwroot \Module \目录中,创建一个名为Web.config的新文件。

2.在Web.config中粘贴以下文本:

 <   configuration  >  
< system.web < span class =code-keyword>>
< httpModules >
< add name = MyModule 类型 = MyModule.SyncModule,MyModule / >
< / httpModules >
< / system.web >
< / configuration >





测试模块;



1.在C:\ Inetpub \Wwwroot \Module目录中,创建一个名为Test.aspx的新.aspx文件。

2.粘贴以下文本到Test.aspx:

 <%@    导入   命名空间  =  MyModule   %>  

< script language = C# runat = 服务器 >
protected void MyModule_OnMyEvent(Object src, EventArgs e)
{
Context.Response.Write(来自My.Module_OnMyEvent的Hello在Global.asax中调用。< br > );
}
< / script >



5.请求Test.aspx页面。您应该看到以下几行文字:

引用:

自定义模块中OnBeginRequest的Hello。

来自Global.asax中调用的MyModule_OnMyEvent的Hello。

来自Test.aspx的Hello。


Hello every one,
i want to implement email module in my asp.net web site.
in that i want inbox,create email,send email,out box ,draft facility.
how to do that till now i have done code for sending mail but not implemented full e mailer pl help to do that.

解决方案

Implement the Module

1. Create a new Visual Studio .NET C# Class Library project named MyModule.
2. Set a reference to the System.Web.dll assembly.
3. Add the following directive to the class:

using System.Web;


4. Rename the class SyncModule.cs, and then change the class definition to reflect this.
5. Implement the IHttpModule interface. Your class definition should appear as follows:

>public class SyncModule : IHttpModule


6. Implement the Init and Dispose methods of the IHttpModule interface as follows:

public void Init(HttpApplication app)
{
   app.BeginRequest += new EventHandler(OnBeginRequest);
}

public void Dispose(){ }



7.Create a delegate for an event as follows:

public delegate void MyEventHandler(Object s, EventArgs e)


8. Define a private local variable of the type MyEventHandler to hold a reference to the event:

private MyEventHandler _eventHandler = null;


9. Create an event that hooks up the delegate to the method in the Global.asax file or class that inherits from the HttpApplication object:

public event MyEventHandler MyEvent
{
   add { _eventHandler += value; }
   remove { _eventHandler -= value; }
}


10. Create the OnBeginRequest method, which hooks up to the BeginRequest event of HttpApplication:

public void OnBeginRequest(Object s, EventArgs e)
{
   HttpApplication app = s as HttpApplication;
   app.Context.Response.Write(&quot;Hello from OnBeginRequest in custom module.&lt;br&gt;&quot;);
   if(_eventHandler!=null)
      _eventHandler(this, null);
}


11. Compile the project.

Deploy the Module

1. Create a new directory under C:\Inetpub\Wwwroot named Module.
2. Create a subdirectory named Bin in the newly created Module directory. The resultant path is C:\Inetpub\Wwwroot\Module\Bin.
3. Copy MyModule.dll from your project's Bin\Debug directory to the C:\Inetpub\Wwwroot\Module\Bin directory.
4. Follow these steps to mark the new Module directory as a Web application:
a. Open Internet Services Manager.
b. Right-click the Module directory, and then click Properties.
c. On the Directory tab, click Create.
d. Click OK to close the Module Properties dialog box.

Configure the System

1. In the C:\Inetpub\Wwwroot\Module\ directory, create a new file named Web.config.
2. Paste the following text in Web.config:

<configuration>
   <system.web>
      <httpModules>
         <add name="MyModule" type="MyModule.SyncModule, MyModule" />
      </httpModules>
   </system.web>
</configuration>



Test the Module;

1. In the C:\Inetpub\Wwwroot\Module directory, create a new .aspx file named Test.aspx.
2. Paste the following text into Test.aspx:

<%@ Import Namespace="MyModule" %>

<script language="C#" runat=server >
protected void MyModule_OnMyEvent(Object src, EventArgs e)
{
  Context.Response.Write("Hello from MyModule_OnMyEvent called in Global.asax.<br>");
}
</script>


5. Request the Test.aspx page. You should see the following lines of text:

Quote:

Hello from OnBeginRequest in custom module.
Hello from MyModule_OnMyEvent called in Global.asax.
Hello from Test.aspx.


这篇关于如何在asp.net网站上实现电子邮件模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆