我想用vc#做一个收发邮件的程序,但是自己又不怎么懂邮件协议,想用别人现成的邮件类。但是又找不到,不知道.net framework中有没有带邮件类。请各位朋友告诉我,在这里谢谢了!~

解决方案 »

  1.   

    找过了,可是好象关于vc#的少,而且找到的也不怎么满意。
    不知道.net framework中有没有自带的呢?
      

  2.   

    看帮助
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwebmailmailmessageclasstopic.htm<%-- 
    This example shows how to send a mail message from a Web Forms page
    using the classes in the System.Web.Mail namespace.
    --%><%@ IMPORT namespace="System.Web.Mail" %><html>
       <script language=C# runat=server>
          void Page_Load()
          {
             if (!IsPostBack)
             {
                txtTo.Text="[email protected]";
                txtFrom.Text="[email protected]";
                txtCc.Text="[email protected]";
                txtBcc.Text="[email protected]";
                txtSubject.Text="Hello";
                txtBody.Text="This is a test message.";
                txtAttach.Text=@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg,"
                   + @"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg";
            txtBodyEncoding.Text = Encoding.ASCII.EncodingName;
            txtBodyFormat.Text="HTML";
             txtPriority.Text="Normal";
            txtUrlContentBase.Text="http://www.contoso.com/images";
            txtUrlContentLocation.Text="http://www.contoso.com/images";
                // Name of relay mail server in your domain.
            txtMailServer.Text="smarthost";
             }
          }      void btnSubmit_Click(Object sender, EventArgs e)
          {
             string sTo, sFrom, sSubject, sBody;
             string sAttach, sCc, sBcc, sBodyEncoding;
             string sBodyFormat, sMailServer, sPriority;
             string sUrlContentBase, sUrlContentLocation;
         int iLoop1;     sTo = txtTo.Text.Trim();
         sFrom = txtFrom.Text.Trim();
         sSubject = txtSubject.Text.Trim();
         sBody = txtBody.Text.Trim();
         sAttach = txtAttach.Text.Trim();
         sCc = txtCc.Text.Trim();
         sBcc = txtBcc.Text.Trim();
         sBodyFormat = txtBodyFormat.Text.Trim();
         sBodyEncoding = txtBodyEncoding.Text.Trim();
         sPriority = txtPriority.Text.Trim();
         sUrlContentBase = txtUrlContentBase.Text.Trim();
         sUrlContentLocation = txtUrlContentLocation.Text.Trim();
         sMailServer = txtMailServer.Text.Trim();     MailMessage MyMail = new MailMessage();
         MyMail.From = sFrom;
         MyMail.To = sTo;
         MyMail.Subject = sSubject;
         MyMail.Body = sBody;
         MyMail.Cc = sCc;
         MyMail.Bcc = sBcc;
         MyMail.UrlContentBase = sUrlContentBase;
         MyMail.UrlContentLocation = sUrlContentLocation;         if (txtBodyEncoding.Text == Encoding.UTF7.EncodingName)
                MyMail.BodyEncoding = Encoding.UTF7;
             else if (txtBodyEncoding.Text == Encoding.UTF8.EncodingName)
                MyMail.BodyEncoding = Encoding.UTF8;
             else
                MyMail.BodyEncoding = Encoding.ASCII;     switch (sBodyFormat.ToUpper())
             {
                case "HTML": 
                   MyMail.BodyFormat = MailFormat.Html;
                   break;
                default: 
                   MyMail.BodyFormat = MailFormat.Text;
                   break;
             }
             
             switch (sPriority.ToUpper())
             {
                case "HIGH": 
                   MyMail.Priority = MailPriority.High;
                   break;
                case "LOW": 
                   MyMail.Priority = MailPriority.Low;
                   break;
                default: 
                   MyMail.Priority = MailPriority.Normal;
                   break;
             }
             
             // Build an IList of mail attachments.
             if (sAttach != "")
             {
                char[] delim = new char[] {','};
                foreach (string sSubstr in sAttach.Split(delim))
                {
                   MailAttachment MyAttachment = new MailAttachment(sSubstr);
                   MyMail.Attachments.Add(MyAttachment);
                }
             }
         
             SmtpMail.SmtpServer = sMailServer;
         SmtpMail.Send(MyMail);
         lblMsg1.Text="C# Message sent to " + MyMail.To;
          }      void btnClear_Click(Object sender, EventArgs e)
          {
             lblMsg1.Text="";
             txtTo.Text="";
             txtFrom.Text="";
             txtSubject.Text="";
             txtBody.Text="";
             txtAttach.Text="";
             txtBcc.Text="";
             txtCc.Text="";
         txtBodyEncoding.Text="";
         txtBodyFormat.Text="";
          txtPriority.Text="";
         txtUrlContentBase.Text="";
         txtUrlContentLocation.Text="";
         txtMailServer.Text="";
             btnSubmit.Text="Submit";
          }
       </script>   <p><h4>Send a new mail message:<h4></p>
       <Form method="Post" action="MailForm.aspx" runat=server>
          <table width="350" bgcolor="#FFFF99">
             <tr>
                <td Align="Right"><b>To:</b></td>
                <td><Asp:Textbox id="txtTo" runat=server/></td>
             </tr>
             <tr>
                <h4><td Align="Right"><b>From:</b></td></h4>
                <td><Asp:Textbox id="txtFrom" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>Subject:</b></td>
                <td><Asp:Textbox id="txtSubject" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>MessageBody:</b></td>
                <td><Asp:Textbox id="txtBody" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>Attachments:</b></td>
                <td><Asp:Textbox id="txtAttach" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>CC:</b></td>
                <td><Asp:Textbox id="txtBcc" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>BCC:</b></td>
                <td><Asp:Textbox id="txtCc" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>BodyEncoding:</b></td>
                <td><Asp:Textbox id="txtBodyEncoding" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>BodyFormat:</b></td>
                <td><Asp:Textbox id="txtBodyFormat" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>Priority:</b></td>
                <td><Asp:Textbox id="txtPriority" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>URL Content Base:</b></td>
                <td><Asp:Textbox id="txtUrlContentBase" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>URL Content Location:</b></td>
                <td><Asp:Textbox id="txtUrlContentLocation" runat=server/></td>
             </tr>
             <tr>
                <td Align="Right"><b>Mail Server:</b></td>
                <td><Asp:Textbox id="txtMailServer" runat=server/></td>
             </tr>
          </table><br>      <asp:button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat=server/>
          <asp:button id="btnClear" Text="Clear" OnClick="btnClear_Click" runat=server/>
          <p><asp:Label id="lblMsg1" runat=server/></p>
       </form>
    </html>
      

  3.   

    我是在vc#中使用的,提示没有System.Web.Mail命名空间。
      

  4.   

    先要添加引用
    using System.Web.Mail;
      

  5.   

    出现下面的错误:error CS0234: 类型或命名空间名称“Mail”在类或命名空间“System.Web”中不存在(是否缺少程序集引用?)
      

  6.   

    添加引用就可以了.System.Web.DLL
      

  7.   

    发邮件的代码 baidu 一下就是
    收邮件的话 我最近只写了收pop3协议的  hotmail就不能收 
    你有兴趣可以去看看
    http://blog.csdn.net/zhangjianying/archive/2006/01/08/573836.aspx
      

  8.   

    http://www.c-sharpcorner.com/UploadFile/ivxivx/SMTPPOP3IMAPLibrary12072005012506AM/SMTPPOP3IMAPLibrary.aspx?ArticleID=01a32901-2e50-4849-9c14-8171c4dbbeff
      

  9.   

    有的,我刚做了一个小小的邮件发送的
    //发送邮件
    System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage(); // SET MESSAGE PARAMETERS 
    myEmail.From = "[email protected]"; 
    myEmail.To = "[email protected]"; 
    myEmail.Subject = "主题"; //主题
    myEmail.BodyFormat = System.Web.Mail.MailFormat.Html; 
    myEmail.Body = "内容" ; //正文
    //SEND THE MESSAGE 
    System.Web.Mail.SmtpMail.Send(myEmail);
      

  10.   

    刚才我做了一个,明明提示成功了,为什么我查看邮件的时候还没有呢?
    代码如下:
                private void button1_Click(object sender, System.EventArgs e)
    {
    MailMessage mm = new MailMessage(); mm.From="[email protected]";
    mm.To="[email protected]";
    mm.Subject="主题";
    mm.Body="我爱你!";
    mm.BodyFormat=MailFormat.Html;
    mm.Priority=MailPriority.High;
    try
    {
    SmtpMail.Send(mm);
    MessageBox.Show("成功了!");
    }
    catch
    {
    MessageBox.Show("错误了!");
    }
    }