.net里使用jmail

来源:互联网 发布:淘宝女装代理货源网 编辑:程序博客网 时间:2024/04/27 20:03

参考网上的一篇文章:http://www.webdn.com/web_file/program/asp.net/0602080139/

内容如下:

ASP.Net环境下使用Jmail组件发送邮件

 

<script type="text/javascript"><!--google_ad_client = "pub-3795982983039684";google_ad_width = 250;google_ad_height = 250;google_ad_format = "250x250_as";google_ad_type = "text_image";google_ad_channel ="";google_color_border = "FFFFFF";google_color_bg = "FFFFFF";google_color_link = "0000FF";google_color_url = "008000";google_color_text = "000000";//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

【摘 要】不同于在Asp中使用Jmail,直接使用 Server.CreateObject就可以了。在.Net环境中,需要进行设置。

 

  配置环境:.Net Framework 1.1,Imai8.02,w3Jmail4.3

实现过程:

不同于在Asp中使用Jmail,直接使用 Server.CreateObject("Jmail.Message")就可以了。在.Net环境中,需要进行设置。

1.安装jmail4.3

2.找到jmail.dll(Program Files/Dimac/w3JMail4下)

3.执行Program Files/Microsoft Visual Studio .NET/FrameworkSDK/Bin/ildasm.exe(可使用Visual Studio .Net 2003 命令提示),

格式如下:tlbimp c:/Program Files/Dimac/w3JMail4/jmail.dll /out:myJmail.dll /namespace:myJmail

生成myJmail.dll后,copy到web的根目录的bin目录。在ASP.Net页面中,用这个方法引用:

Jmail.aspx

<%@ Page Language="C#" ContentType="text/html"%>

<%@ Import Namespace="myJmail" %>

<script runat="server">

protected void Page_Load(Object Src, EventArgs E)

{

 

Message jmail=new Message();

jmail.From="sss";

jmail.AddRecipient("lsg@ckocoo.com",null,null);

jmail.MailServerUserName="brookes";

jmail.MailServerPassWord="walkor";

jmail.Subject="jmail c#";

jmail.Send("mail.lsg.com",false);

</script>

 

Tlbimp:

Microsoft .Net Framework Type Library to Assembly Converter

 

按上面的方法添加引用后,还是不能发送。老出错:

The message was undeliverable. All servers failed to receive the message

不知道什么原因.邮件服务器,用户名和密码放在本机的outlook express的设置里可以发信收信。页面上就出错。

加了Response.ContentType="text/html"; 还是这个错误。本机的smtp服务关了没用。防火墙关了,突然不出错了,刷了五下也没错。打开本机的outlook express,收到五封邮件。

我用的是VirusScan Enterprise杀毒软件,后来在控件台-访问保护-端口阻挡-要阻挡的端口-[禁止大量发送邮件的蠕虫病毒发送邮件-双击-已排除进程-添加aspnet_wp.exe(我是这个进程).就可以发邮件了。

后来没有用JMAIL,用.NET类库了,网上有现成的资料,如下:

MailMessage mail = new MailMessage();

mail.To = "xxxxxx@hotmail.com";
mail.Bcc = "xxxxxxx@gmail.com";
mail.From = "xxxxx@abc.com";
mail.BodyFormat = MailFormat.Text;
mail.Subject = "Subject of this Email " + System.DateTime.Now.ToString();
mail.Body = "Body of this message.";


SmtpMail.SmtpServer="www.abc.com";

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "loginname");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Password");

SmtpMail.Send(mail);

原创粉丝点击