日期:2014-05-18  浏览次数:20464 次

asp.net c#邮件收发?
大家好:
  我没写过邮件收发系统,
现在要用ASP.NET C#写个邮件收发系统,要可以发邮件,可以收邮件,但不知道怎么下手?
在网上看到说 ASP.NET里有自带的System.net.Mail类可以实现,
有的说自带的类只能实现发,不能收,收要用JMAIL,
但这些我都没用过,
不知道该怎么写?
好像程序写好,还要配置SMTP服务?
如果我先在我本地实现收发做个测试,需要怎么配置?
请高手们给我个思路,实现步骤,有代码更好,最好能有注释,谢谢。

------解决方案--------------------
C# code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Text;
using System.Net;

/// <summary>
///SendMail 的摘要说明
/// </summary>
public class SendMail
{
    private string _mailStmp;

    public string MailStmp
    {
        get { return _mailStmp; }
        set { _mailStmp = value; }
    }
    private string _mailFrom;

    public string MailFrom
    {
        get { return _mailFrom; }
        set { _mailFrom = value; }
    }
    private string _mailPwd;

    public string MailPwd
    {
        get { return _mailPwd; }
        set { _mailPwd = value; }
    }
    private string _mailTo;

    public string MailTo
    {
        get { return _mailTo; }
        set { _mailTo = value; }
    }
    private string _mailTitle;

    public string MailTitle
    {
        get { return _mailTitle; }
        set { _mailTitle = value; }
    }
    private string _mailContent;

    public string MailContent
    {
        get { return _mailContent; }
        set { _mailContent = value; }
    }
    public static void Send(SendMail mailInfo)
    {
        /*发件人的信息*/
        string smtp = mailInfo.MailStmp; //发信人所用邮箱的服务器 
        string mailForm = mailInfo.MailFrom; //发件人的邮箱 
        string mailPwd = mailInfo.MailPwd; //发件人的密码 
        string mailTo = mailInfo.MailTo; //收件人信息 
        string mailTitle = mailInfo.MailTitle; //邮件标题 
        string mailContent = mailInfo.MailContent; //邮件内容 

        SmtpClient client = new SmtpClient(smtp, 25);
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential(mailForm, mailPwd);
        /*指定如何处理待发的邮件*/
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        MailMessage message = new MailMessage(mailForm, mailTo, mailTitle, mailContent);
        message.BodyEncoding = Encoding.Default;
        message.IsBodyHtml = true;

        client.Send(message);
        //try
        //{
        //    MailInfo mi = new MailInfo();
        //    mi.MailStmp = ""
        //    mi.MailFrom = "@.com";
        //    mi.MailPwd = "";
        //    mi.MailTo = "beyondmj0.student@sina.com";
        //    mi.MailTitle = "Test For Fucking";
        //    mi.MailContent = "<marquee>123</marquee>";
        //    SendMail(mi);
        //}
        //catch (Exception ex)
        //{
        //    Console.WriteLine(ex.Message);
        //}
    }
}

------解决方案--------------------
参考
http://www.cnblogs.com/smallfa/articles/929962.html
http://www.cnblogs.com/zengjun1980/articles/1074825.html
------解决方案--------------------
http://www.cnblogs.com/yank/archive/2008/08/03/1258428.html
http://www.cnblogs.com/voswin/articles/1281522.html
------解决方案--------------------
http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html
------解决方案--------------------
/**//// <summary>
/// 邮件初始化
/// 为了简单,自己发个自己
/// </summary>
/// <returns></returns>
public MailMessage InitMail(string Address)
{
MailMessage mail = new MailMessage();
//发件人
mail.From = new MailAddress(Address);