看system.web.mail的说明,十分钟就可以写出来

解决方案 »

  1.   

    MailMessage msgMail = new MailMessage();
    msgMail.To = "[email protected]";
    msgMail.From = "[email protected]";
    msgMail.Subject = "Attachment Test";
    msgMail.BodyFormat = MailFormat.Text;
    msgMail.Body = "Check out the attachment!";
    msgMail.Attachments.Add(new MailAttachment("c:\\test.xml"));
    SmtpMail.Send(msgMail);
    Response.Write("Email was queued to disk");
      

  2.   

    http://blog.csdn.net/wthorse/archive/2006/06/13/794705.aspx
      

  3.   

    vs2003 引用 System.Web.Mail命名空间
    vs2005 引用 System.Net.Mail命名空间,安全性得到了增强...
    try
    {
    //创建邮件消息
    MailMessage objMailMessage = new MailMessage();
    objMailMessage.From = System.Configuration.ConfigurationSettings.AppSettings["mailfrom"];//源邮件地址"[email protected]"
    objMailMessage.To = System.Configuration.ConfigurationSettings.AppSettings["mailto"];//目的邮件地址"[email protected]"
    objMailMessage.Subject = "邮件的标题";//发送邮件的标题
    objMailMessage.Body = "邮件的内容";//发送邮件的内容

    string user = System.Configuration.ConfigurationSettings.AppSettings["mailuser"];//源邮件地址用户名
    string psw = (System.Configuration.ConfigurationSettings.AppSettings["mailpsw"]);//源邮件地址用户密码
    //基本权限
    objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    //用户名
    objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user) ;
    //密码
    objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", psw);
    //如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为: 554 : Client host rejected: Access denied 
    //SMTP地址
    SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["mailsvr"];//"smtp.163.com"
    //开始发送邮件
    SmtpMail.Send(objMailMessage);
    }
    catch(Exception ex)
    {
    Log4Net.WriteLog("Exec_MailSend ERROR="+ex.ToString());
    }
    ...
      

  4.   

    2005——string server="smtp.163.com";
    string file = "e:\xxx.rar";
    MailMessage message = new System.Net.Mail.MailMessage("[email protected]", "[email protected]", "正文", "标题");
    Attachment data = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
    System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
             disposition.CreationDate = File.GetCreationTime(file);
             message.Attachments.Add(data);
            SmtpClient client = new SmtpClient(server);
            client.Credentials = new NetworkCredential("用户名", "密码");
            client.Send(message);
            data.Dispose();
      

  5.   

    大哥啊。。
    client.Credentials = new NetworkCredential("用户名", "密码");
    这个NetworkCredential是您自己定义的吧
    给个解释啊
      

  6.   

    大哥啊。。
    client.Credentials = new NetworkCredential("用户名", "密码");
    这个NetworkCredential是您自己定义的吧
    给个解释啊
    -----------------------------------------------------------
    using System.Net;
      

  7.   

    http://www.51aspx.com/CV/JH1GEZ9ACZA70
      

  8.   

    测试过了,已经通过了<%@ Page Language="C#" %><%@ Import Namespace="System.Net.Mail" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">    
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();        msg.From = new MailAddress("[email protected]");
            msg.To.Add(new MailAddress(TextBox1.Text));
         
            msg.Subject = TextBox2.Text;
            msg.Body = TextBox3.Text;
            string attachFile;
            attachFile=FileUpload1.FileName;        System.Net.Mail.Attachment mailadd = new Attachment(FileUpload1.PostedFile.InputStream, attachFile);
            msg.Attachments.Add(mailadd);        SmtpClient smt = new SmtpClient();
            smt.Send(msg);
                    
            
        }
    </script><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            &nbsp;<asp:Label ID="Label1" runat="server" Text="收件人地址:"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server" Width="216px"></asp:TextBox><br />
            <br />
            <asp:Label ID="Label2" runat="server" Text="主题:"></asp:Label>
            <asp:TextBox ID="TextBox2" runat="server" Width="219px"></asp:TextBox><br />
            <br />
            <asp:Label ID="Label4" runat="server" Text="附件:"></asp:Label>
            &nbsp;
            <asp:FileUpload ID="FileUpload1" runat="server" /><br />
            <br />
            <asp:Label ID="Label3" runat="server" Text="内容:"></asp:Label><br />
            <asp:TextBox ID="TextBox3" runat="server" Height="176px" Width="348px"></asp:TextBox><br />
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" Text="发送" OnClick="Button1_Click" />
            <asp:Button ID="Button2" runat="server" Text="取消" /></div>
        </form>
    </body>
    </html>然后在web.config里面配置下:
    <?xml version="1.0"?>
    <configuration>
    <system.net>
        //配置smtp
        <mailSettings>
          <smtp   deliveryMethod="Network"  from="[email protected]">
            <network  defaultCredentials="false" host="smtp.126.com" port="25" userName="yuzhen20" password="tramper11"/>
            
          </smtp>
        </mailSettings>
      </system.net> <connectionStrings/>
    <system.web>
        <globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
    <compilation debug="true"/>
    <authentication mode="Windows"/>

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    </system.web>
    </configuration>