有谁用vs 2003 + c# 做过电子邮件系统,给点提示?或者提供代码,250分 如题,最近要做邮件系统,大家给点意见,通通给分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要做ASP.net邮件系统吗? 下面代码是发送邮件的,接收邮件比这个长点public void Mail_Send(Object src,EventArgs e){ MailMessage MyMsg=new MailMessage(); MyMsg.From =tbFrom.Text; MyMsg.To=tbTo.Text; //接收地址 MyMsg.Subject=tbSubject.Text; MyMsg.Priority=(MailPriority)ddlPriority.SelectedIndex; Mymsg.BodyFormat=(MailFormat)ddlBodyFormat.SelectedIndex; MyMsg.Body=tbBody.Text; HttpPostedFile hpfFile=AttachFile.PostedFile; if(hpfFile.FileName!="") { char[] de={'\\'}; string[] AFileName=hpfFile.FileName.Split(de); string strFileName=AFileName[AFileName.Length-1]; string strPath =Server.MapPath(".")+"\\Temp\\"+strFilename; hpfFile.SaveAs(strPath); MyMsg.Attachments.Add(new MailAttachment(strPath)); } try { SmtpMail.Send(MyMsg); //发送 lblShowMsg.Text="OK!"; tbTo.Text=""; tbSubject.Text=""; tbBody.Text=""; ddlPriority.SelectedIndex=1; ddlBodyFormat.SelectedIndex=0; } catch(Exception ee) { lblShowMsg.Text="发送失败!"+ee.ToString(); }} codeproject 有相关开元项目.去找找 using System;using System.Web.Mail;namespace egxsun{ /// /// SystemMail 的摘要说明。 /// public class SystemMail { private string _adminEmail; private string _smtpServer = "localhost"; private string _password; private string _userName; public SystemMail() { } public string AdminEmail { get{return _adminEmail;} set{_adminEmail = value;} } public string SmtpServer { get{return _smtpServer;} set{_smtpServer = value;} } public string Password { get{return _password;} set{_password = value;} } public string UserName { get{return _userName;} set{_userName = value;} } public bool Send(string to, string from, string subject, string message) { try { MailMessage em = new MailMessage(); em.To = to; em.From = from; em.Subject = subject; em.Body = message; //Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8) if(this.UserName != null && this.Password != null) { em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here } SmtpMail.SmtpServer = this.SmtpServer; SmtpMail.Send(em); return true; } catch { return false; } } }} using System;using System.Web.Mail;namespace DAL{ /// <summary> /// MailFactroy 的摘要说明。 /// </summary> public class MailFactory { private string mailFromAddress; private string mailSubject; private string mailToAddress; private string body; private string mailSmtpServer; private string mailUsername; private string mailPassword; private string myAttachments; private string appPath; public MailFactory() { } public string MyAttachments { get { return myAttachments; } set { myAttachments=value; } } public string AppPath { get { return appPath; } set { appPath=value; } } public string MailFromAddress { get { return mailFromAddress; } set { mailFromAddress=value; } } public string MailSubject { get { return mailSubject; } set { mailSubject=value; } } public string MailToAddress { get { return mailToAddress; } set { mailToAddress=value; } } public string Body { get { return body; } set { body=value; } } public string MailSmtpServer { get { return mailSmtpServer; } set { mailSmtpServer=value; } } public string MailUsername { get { return mailUsername; } set { mailUsername=value; } } public string MailPassword { get { return mailPassword; } set { mailPassword=value; } } public void SendMail() { //bool isSended; //isSended=false; MailMessage mailObj = new MailMessage(); // 设置邮件的发送及接收地址 mailObj.From = MailFromAddress; mailObj.To = MailToAddress; mailObj.Subject = MailSubject; mailObj.Body = Body; // html格式的邮件 mailObj.BodyFormat = MailFormat.Html; //mailObj.BodyEncoding=System.Text.Encoding.UTF8; // 设置为高级优先权 mailObj.Priority = MailPriority.High; // 为邮件添加附件 // 注意:这里我们创建了一个mailattachment对象添加一个附件到邮件中 //mailObj.Attachments.Add(new MailAttachment("c:\\test.doc")); /*if(AppPath!=null) { string[] ArrAttachment; char[] separator={','}; ArrAttachment=MyAttachments.Split(separator); foreach(string tmp in ArrAttachment) { mailObj.Attachments.Add(new MailAttachment(AppPath+tmp)); } } // 使用SmtpMail对象发送邮件 mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", MailUsername); //set your username here mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", MailPassword); //set your password here */ SmtpMail.SmtpServer=MailSmtpServer; SmtpMail.Send(mailObj); //return isSended; } }} 这个 codeproject上有开源的project的 真的我没做过,做个模拟的希望楼主满意using System;using System.Web.Mail;namespace SmtpMailDemo{ class Class1 { [STAThread] static void Main(string[] args) { MailMessage mm=new MailMessage(); mm.From="[email protected]"; mm.To="[email protected]"; mm.Subject="Hello"; mm.Priority=MailPriority.High; mm.BodyFormat=MailFormat.Text; mm.Body="Demo"; MailAttachment ma=new MailAttachment(@"c:\demo.txt",MailEncoding.Base64); mm.Attachments.Add(ma); try { SmtpMail.SmtpServer="smtp.263.net"; SmtpMail.Send(mm); } catch(Exception e) { Console.WriteLine(e.Message); } } }} public void Mail_Send(Object src,EventArgs e){ MailMessage MyMsg=new MailMessage(); MyMsg.From =tbFrom.Text; MyMsg.To=tbTo.Text; //接收地址 MyMsg.Subject=tbSubject.Text; MyMsg.Priority=(MailPriority)ddlPriority.SelectedIndex; Mymsg.BodyFormat=(MailFormat)ddlBodyFormat.SelectedIndex; MyMsg.Body=tbBody.Text; HttpPostedFile hpfFile=AttachFile.PostedFile; if(hpfFile.FileName!="") { char[] de={'\\'}; string[] AFileName=hpfFile.FileName.Split(de); string strFileName=AFileName[AFileName.Length-1]; string strPath =Server.MapPath(".")+"\\Temp\\"+strFilename; hpfFile.SaveAs(strPath); MyMsg.Attachments.Add(new MailAttachment(strPath)); } try { SmtpMail.Send(MyMsg); //发送 lblShowMsg.Text="OK!"; tbTo.Text=""; tbSubject.Text=""; tbBody.Text=""; ddlPriority.SelectedIndex=1; ddlBodyFormat.SelectedIndex=0; } catch(Exception ee) { lblShowMsg.Text="发送失败!"+ee.ToString(); }} 难点主要是收到的邮件怎么样把它分离出邮件主题,时间,收件人,发件人,优先级,附件等等 有没有分离这些的代码,或者给我说说思路,因为各个邮件服务器的发送邮件有点不一样的所以收到的邮件就不一样,比如说分离出了126.com邮件服务器里的邮件但是换一个邮件服务器,就不行了。这怎么解决?????????? 纠错 这个问题有人会吗? 基于C#编写的 32位 WinForm程序 ,理论上可以使用多少内存?请高手指点一下。 存储过程 [求助:]C# RichTextBox.AutoWordSelection 属性是怎么实现的? 急急急急急急急急急急急急急,請進! 100分求助大神、winform自定义控件可以通过属性设计调用某个类方法吗? [急]100求助将一段非托管C++代码转换成C#调用,在线等,解决马上给分 上下方向键??? GDI+处理,保存图像问题 b/s结构的系统的公共变量? 一个动态链接库的问题
public void Mail_Send(Object src,EventArgs e)
{
MailMessage MyMsg=new MailMessage();
MyMsg.From =tbFrom.Text;
MyMsg.To=tbTo.Text; //接收地址
MyMsg.Subject=tbSubject.Text;
MyMsg.Priority=(MailPriority)ddlPriority.SelectedIndex;
Mymsg.BodyFormat=(MailFormat)ddlBodyFormat.SelectedIndex;
MyMsg.Body=tbBody.Text; HttpPostedFile hpfFile=AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
char[] de={'\\'};
string[] AFileName=hpfFile.FileName.Split(de);
string strFileName=AFileName[AFileName.Length-1];
string strPath =Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
MyMsg.Attachments.Add(new MailAttachment(strPath));
}
try
{
SmtpMail.Send(MyMsg); //发送
lblShowMsg.Text="OK!";
tbTo.Text="";
tbSubject.Text="";
tbBody.Text="";
ddlPriority.SelectedIndex=1;
ddlBodyFormat.SelectedIndex=0;
}
catch(Exception ee)
{
lblShowMsg.Text="发送失败!"+ee.ToString();
}
}
using System.Web.Mail;namespace egxsun
{
/// /// SystemMail 的摘要说明。 /// public class SystemMail { private string _adminEmail; private string _smtpServer = "localhost"; private string _password; private string _userName; public SystemMail() { } public string AdminEmail { get{return _adminEmail;} set{_adminEmail = value;} } public string SmtpServer { get{return _smtpServer;} set{_smtpServer = value;} } public string Password { get{return _password;} set{_password = value;} } public string UserName { get{return _userName;} set{_userName = value;} } public bool Send(string to, string from, string subject, string message) { try { MailMessage em = new MailMessage(); em.To = to; em.From = from; em.Subject = subject; em.Body = message; //Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8) if(this.UserName != null && this.Password != null) { em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here } SmtpMail.SmtpServer = this.SmtpServer;
SmtpMail.Send(em); return true; } catch { return false; } } }
}
using System.Web.Mail;namespace DAL
{
/// <summary>
/// MailFactroy 的摘要说明。
/// </summary>
public class MailFactory
{
private string mailFromAddress;
private string mailSubject;
private string mailToAddress;
private string body;
private string mailSmtpServer;
private string mailUsername;
private string mailPassword;
private string myAttachments;
private string appPath;
public MailFactory()
{
}
public string MyAttachments
{
get
{
return myAttachments;
}
set
{
myAttachments=value;
} } public string AppPath
{
get
{
return appPath;
}
set
{
appPath=value;
} } public string MailFromAddress
{
get
{
return mailFromAddress;
}
set
{
mailFromAddress=value;
}
} public string MailSubject
{
get
{
return mailSubject;
}
set
{
mailSubject=value;
}
} public string MailToAddress
{
get
{
return mailToAddress;
}
set
{
mailToAddress=value;
}
} public string Body
{
get
{
return body;
}
set
{
body=value;
}
} public string MailSmtpServer
{
get
{
return mailSmtpServer;
}
set
{
mailSmtpServer=value;
}
} public string MailUsername
{
get
{
return mailUsername;
}
set
{
mailUsername=value;
}
} public string MailPassword
{
get
{
return mailPassword;
}
set
{
mailPassword=value;
}
} public void SendMail()
{
//bool isSended;
//isSended=false; MailMessage mailObj = new MailMessage(); // 设置邮件的发送及接收地址
mailObj.From = MailFromAddress; mailObj.To = MailToAddress; mailObj.Subject = MailSubject;
mailObj.Body = Body; // html格式的邮件
mailObj.BodyFormat = MailFormat.Html;
//mailObj.BodyEncoding=System.Text.Encoding.UTF8; // 设置为高级优先权
mailObj.Priority = MailPriority.High; // 为邮件添加附件
// 注意:这里我们创建了一个mailattachment对象添加一个附件到邮件中
//mailObj.Attachments.Add(new MailAttachment("c:\\test.doc"));
/*if(AppPath!=null)
{
string[] ArrAttachment;
char[] separator={','};
ArrAttachment=MyAttachments.Split(separator);
foreach(string tmp in ArrAttachment)
{
mailObj.Attachments.Add(new MailAttachment(AppPath+tmp));
}
} // 使用SmtpMail对象发送邮件
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", MailUsername); //set your username here
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", MailPassword); //set your password here */ SmtpMail.SmtpServer=MailSmtpServer;
SmtpMail.Send(mailObj);
//return isSended;
}
}
}
using System;
using System.Web.Mail;namespace SmtpMailDemo
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
MailMessage mm=new MailMessage();
mm.From="[email protected]";
mm.To="[email protected]";
mm.Subject="Hello";
mm.Priority=MailPriority.High;
mm.BodyFormat=MailFormat.Text;
mm.Body="Demo";
MailAttachment ma=new MailAttachment(@"c:\demo.txt",MailEncoding.Base64);
mm.Attachments.Add(ma);
try
{
SmtpMail.SmtpServer="smtp.263.net";
SmtpMail.Send(mm);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
{
MailMessage MyMsg=new MailMessage();
MyMsg.From =tbFrom.Text;
MyMsg.To=tbTo.Text; //接收地址
MyMsg.Subject=tbSubject.Text;
MyMsg.Priority=(MailPriority)ddlPriority.SelectedIndex;
Mymsg.BodyFormat=(MailFormat)ddlBodyFormat.SelectedIndex;
MyMsg.Body=tbBody.Text; HttpPostedFile hpfFile=AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
char[] de={'\\'};
string[] AFileName=hpfFile.FileName.Split(de);
string strFileName=AFileName[AFileName.Length-1];
string strPath =Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
MyMsg.Attachments.Add(new MailAttachment(strPath));
}
try
{
SmtpMail.Send(MyMsg); //发送
lblShowMsg.Text="OK!";
tbTo.Text="";
tbSubject.Text="";
tbBody.Text="";
ddlPriority.SelectedIndex=1;
ddlBodyFormat.SelectedIndex=0;
}
catch(Exception ee)
{
lblShowMsg.Text="发送失败!"+ee.ToString();
}
}
有没有分离这些的代码,或者给我说说思路,因为各个邮件服务器的发送邮件有点不一样的
所以收到的邮件就不一样,比如说分离出了126.com邮件服务器里的邮件
但是换一个邮件服务器,就不行了。
这怎么解决??????????