• 全部
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

ASP.NET 如何发信??

yuna103 2004-10-28 10:54:40
ASP.NET 如何发信??

ASP中用Jmail发信! Asp.net 也要用Jmail吗?? 最一般用什么方法呢?
...全文
71 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
heroetigen 2004-10-28
也就是说要自已还要有那个SMTP服务器是吧?
不过看起来比Jmail简单多了!~:)
回复
fyqr2000 2004-10-28
发到对方对,你要不是收要这个作什么
回复
changlin365 2004-10-28
用 using System.Web.Mail
回复
活靶子哥哥 2004-10-28
需要主机开启smtp服务
回复
yuna103 2004-10-28
发邮件服务器在哪里?虚拟主机商给提供吗?
回复
oyff 2004-10-28
SmtpMail.SmtpServer = "..."
SmtpMail.Send("...")
回复
活靶子哥哥 2004-10-28
using System;
using System.Text;
using System.Web.Mail;
using System.Web.Util ;
namespace ShangGu.Bidding
{
/// <summary>
/// CommonFunction 的摘要说明。
/// </summary>
public class CommonFunction
{
public CommonFunction()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

/// <summary>
/// 本地smtp发送Email
/// </summary>
/// <param name="MailTo">接收Email地址</param>
/// <param name="MailFrom">发送翻Email地址</param>
/// <param name="MailSubject">邮件主题</param>
/// <param name="MailBody">邮件内容</param>
/// <param name="isHtml">是否为Html格式</param>
/// <returns>布尔值表示发送成功与否</returns>
public static bool SendEmail(string MailTo,string MailFrom,string MailSubject,string MailBody,bool isHtml)
{
// bool isOk = false;
// MailMessage myMail = new MailMessage();
// myMail.BodyEncoding = Encoding.GetEncoding("GB2312");
// myMail.BodyFormat = (isHtml) ? MailFormat.Html:MailFormat.Text;
// myMail.To = MailTo;
// myMail.From = MailFrom;
// myMail.Subject = MailSubject;
// myMail.Body = MailBody;
// myMail.Priority = MailPriority.High;
// try
// {
// SmtpMail.Send(myMail);
// isOk = true;
// }
// catch{}
// return isOk;

return SendEmail(MailTo,MailFrom,MailSubject,MailBody,isHtml,"127.0.0.1",null,null);

}
/// <summary>
/// 使用指定的smtp服务器发送email
/// </summary>
/// <param name="MailTo">接收Email地址</param>
/// <param name="MailFrom">发送翻Email地址</param>
/// <param name="MailSubject">邮件主题</param>
/// <param name="MailBody">邮件内容</param>
/// <param name="isHtml">是否为Html格式</param>
/// <param name="SmtpServerAddress">smtp服务器</param>
/// <param name="SmtpUserName">smtp服务器上的用户名</param>
/// <param name="SmtpUserPassWord">smtp服务器上的密码</param>
/// <returns>布尔值表示发送成功与否</returns>
public static bool SendEmail(string MailTo,string MailFrom,string MailSubject,string MailBody,bool isHtml,string SmtpServerAddress,string SmtpUserName,string SmtpUserPassWord)
{
bool isOk =false;
MailMessage myMail = new MailMessage();
myMail.BodyEncoding = Encoding.GetEncoding("GB2312");
myMail.BodyFormat = (isHtml) ? MailFormat.Html:MailFormat.Text;
myMail.To = MailTo;
myMail.From = MailFrom;
myMail.Subject = MailSubject;
myMail.Body = MailBody;
myMail.Priority = MailPriority.High;
if(SmtpUserName != null && SmtpUserPassWord != null)
{
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SmtpUserName); //Smtp Server 上的用户名
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SmtpUserPassWord); //Smtp Server 上的密码


}
SmtpMail.SmtpServer = SmtpServerAddress;//Smtp Server 地址
try
{
SmtpMail.Send(myMail);
isOk = true;
}
catch
{
}
return isOk;

}
}
}
回复
yuna103 2004-10-28
既然可以用 using System.Web.Mail; 为什么还要Jmail呢,还要安装组件?
回复
baihecheng 2004-10-28
up
回复
MeE 2004-10-28
可以用jmail
回复
iceflying1 2004-10-28
using System.Web.Mail;
回复
蛙才 2004-10-28
首先应用C:\WINNT\system32\cdosys.dll.
这个方法我个人认为最简单,而且最实用的,其他如using System.Web.Mail是最不可靠的。
using System;

using CDO;

namespace Wacle.Email

{

public enum EmailTypeFormat

{

Text=0,

HTML=1

}



/// <summary>

/// WEmail 的摘要说明。

/// </summary>

public sealed class WEmail

{

private string sendEmailAddress;

private string sendPassword;

private string smtpServer;

private string sendUserName;

private int smtpServerPort;



private string subject;

private string mailTo;

private string mailFrom;

private string mailCC;

private string mailBCC;

private string mailContent;

private string attachFilePath;



private EmailTypeFormat emailtype;

private CDO.ConfigurationClass cdoConf;

public WEmail()

{

//

// TODO: 在此处添加构造函数逻辑

//

cdoConf=new ConfigurationClass();

}



/// <summary>

/// 获取或设置发送者的EMAIL地址

/// </summary>

public String SendEmailAddress

{

get{ return sendEmailAddress;}

set{ this.sendEmailAddress=value;}

}



/// <summary>

/// 获取或设置邮件帐号的密码

/// </summary>

public String SendPassword

{

get{ return sendPassword;}

set{ this.sendPassword=value;}

}



/// <summary>

/// 获取或设置SMTP服务器

/// </summary>

public String SmtpServer

{

get{ return this.smtpServer;}

set{ this.smtpServer=value;}

}



/// <summary>

/// 获取或设置发送者姓名

/// </summary>

public String SendUserName

{

get{ return this.sendUserName;}

set{ this.sendUserName=value;}

}



/// <summary>

/// 获取或设置SMTP服务器端口号

/// </summary>

public int SmtpServerPort

{

get{ return this.smtpServerPort;}

set{ this.smtpServerPort=value;}

}



/// <summary>

/// 获取或设置邮件主题

/// </summary>

public String MailSubject

{

get{ return this.subject;}

set{this.subject=value;}

}



/// <summary>

/// 获取或设置收件人地址

/// </summary>

public String MailTo

{

get{ return this.mailTo;}

set{ this.mailTo=value;}

}



/// <summary>

/// 获取或设置发件人地址

/// </summary>

public String MailFrom

{

get{ return this.mailFrom;}

set{ this.mailFrom=value;}

}



/// <summary>

/// 获取或设置抄送人地址

/// </summary>

public String MailCC

{

get{return this.mailCC;}

set{this.mailCC=value;}

}



/// <summary>

/// 获取或设置暗送人

/// </summary>

public String MailBCC

{

get{return this.mailBCC;}

set{this.mailBCC=value;}

}



/// <summary>

/// 获取或设置附件地址

/// </summary>

public String MailAttachPath

{

get{return this.attachFilePath;}

set{ this.attachFilePath=value;}

}



/// <summary>

/// 获取或设置Email内容

/// </summary>

public String MailContent

{

get{ return this.mailContent;}

set{ this.mailContent=value;}

}



/// <summary>

/// 获取或设置Email格式

/// </summary>

public EmailTypeFormat EmailType

{

get{ return this.emailtype;}

set{ this.emailtype=value;}

}



/// <summary>

/// 发送EMAIL

/// </summary>

public void SendEmail()

{

cdoConf.Fields[CdoConfiguration.cdoSMTPServer].Value=this.SmtpServer;

cdoConf.Fields[CdoConfiguration.cdoSMTPServerPort].Value=this.smtpServerPort;

cdoConf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value=CdoProtocolsAuthentication.cdoBasic;



cdoConf.Fields[CdoConfiguration.cdoSendEmailAddress].Value=this.SendEmailAddress;

cdoConf.Fields[CdoConfiguration.cdoSendUserName].Value=this.SendUserName;

cdoConf.Fields[CdoConfiguration.cdoSendPassword].Value=this.SendPassword;



cdoConf.Fields.Update();





MessageClass message=new MessageClass();

message.Configuration=cdoConf;

message.Subject=this.MailSubject;

switch(this.EmailType)

{

case EmailTypeFormat.Text:

message.TextBody=this.MailContent;

break;

case EmailTypeFormat.HTML:

message.HTMLBody=this.MailContent;

break;

}

message.From=this.MailFrom;

message.To=this.MailTo;

message.CC=this.MailCC;

message.BCC=this.MailBCC;





if(this.MailAttachPath!=null)

{

string[] attach=this.MailAttachPath.Split(';');

for(int i=0;i<attach.Length;i++)

message.AddAttachment(attach[i],this.SendUserName,this.SendPassword);

}

try

{

message.Send();

}

catch

{

throw;

}

}

}

}
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2004-10-28 10:54
社区公告
暂无公告