在执行的过程中执行调用方法!!
public static void SendMail(string strSmtpServer, string strForm, string strFormPass, string strto, string strSubject, string strBody)
    {
        System.Net.Mail.SmtpClient clint = new System.Net.Mail.SmtpClient(strSmtpServer);
        clint.UseDefaultCredentials = false;
        clint.Credentials = new System.Net.NetworkCredential(strForm, strFormPass);
        clint.DeliveryMethod = SmtpDeliveryMethod.Network;
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strForm, strto, strSubject, strBody);
        System.Text.Encoding.GetEncoding("gb2312");
        message.SubjectEncoding = Encoding.GetEncoding("gb2312");
        message.BodyEncoding = Encoding.GetEncoding("gb2312");
        message.IsBodyHtml = true;
        message.Priority = MailPriority.Normal;
        message.IsBodyHtml = true;
        //string strFj;
        //Attachment returnValue ;
        //Attachment.CreateAttachmentFromString(strFj,);        //message.Attachments.Add(new System.Net.Mail.Attachment(StrFj));
        clint.Send(message);
    }

解决方案 »

  1.   

    用jmail吧,引用之后就可以发送了,感觉挺好用的。
      

  2.   

    /// <summary>
        /// 发送邮件    /// </summary>
        /// <param name="strSmtpServer">smtp地址</param>
        /// <param name="UserName">用户名</param>
        /// <param name="Password">密码</param>
        /// <param name="strFrom">发信人地址</param>
        /// <param name="strto">收信人地址</param>
        /// <param name="strSubject">邮件标题</param>
        /// <param name="strBody">邮件正文</param>
        public void SendMail(string strSmtpServer, string UserName, string Password, string strFrom, string strto, string strSubject, string strBody, string strFileName)
        {
            try
            {
                //生成一个 使用SMTP发送邮件的客户端对象            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(strSmtpServer);            //表示以当前登录用户的默认凭据进行身份验证
                client.UseDefaultCredentials = true;            //包含用户名和密码
                client.Credentials = new System.Net.NetworkCredential(UserName, Password);            //指定如何发送电子邮件。            
                //Network                      电子邮件通过网络发送到 SMTP 服务器。  
                //PickupDirectoryFromIis       将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。  
                //SpecifiedPickupDirectory     将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。              client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;            //建立邮件对象 
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody);
                
                //定义邮件正文,主题的编码方式
                message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
                message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");            //获取或设置一个值,该值指示电子邮件正文是否为 HTML。 
                message.IsBodyHtml = false;            //指定邮件优先级            
                message.Priority = System.Net.Mail.MailPriority.Normal;            //添加附件
                //System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(@"f:/baihe.txt"); 
                if (strFileName != "" && strFileName != null)
                {
                    Attachment data = new Attachment(strFileName);
                    message.Attachments.Add(data);
                }            //发件人身份验证            
                client.Credentials = new System.Net.NetworkCredential(strFrom, Password);
                //发送            
                client.Send(message);
            }
            catch
            {
                throw;
            }
        }
    将发送者的信息存入到数据库或是配制信息。
      

  3.   

    03的是引用system.web.mail跟05的不同!你把发送不了的错误代码帖出来看看你哪个地方写错了!
      

  4.   

    对了  忘记给大家说明白了 我用的是vs2003没有system.net.mail的 
    要是有用jmail成功的朋友,希望你帮帮我 给出你的运行成功地代码  ,小弟也期待用过openmail.net的也朋友来指教
      

  5.   

    发送错误就是和smtp服务器连接失败
      

  6.   

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim mail As New jmail.Message        Dim subject As String
            Dim body As String
            Dim eamil As String = TextBox1.Text.Trim        mail.Logging = True
            mail.Silent = False
            mail.Charset = "GB2312"
            mail.ContentType = "text/html"        mail.From = "[email protected]"
            mail.MailServerUserName = "[email protected]"
            mail.MailServerPassWord = "*****密码"
            Dim content As String
            content = "<p>尊敬的用户:****</p>"
            content += "<p>&nbsp;&nbsp;&nbsp; 您好!</p>"
            content += "<p>&nbsp;&nbsp;&nbsp; 您在我这里注册的那个号码,这几天多半不的行.</p>"
            content += "<p>&nbsp;&nbsp;&nbsp; 顺便送你一张美女图片<img border=""0"" id=""img1"" src=""http://www.12705.com/Html/11882.jpg""/></p>"
            content += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;小宝</p>"        subject = "主题"
            mail.FromName = "*****服务平台"
            mail.AddRecipient(eamil.ToString(), "", "")        mail.Subject = subject
            mail.HTMLBody = content
            mail.Priority = 3        If mail.Send("smtp.qq.com") = True Then
                alert("邮件发送成功!")
            Else
                alert("邮件发送失败!")
            End If
                 
        End Sub
    VB的你自己稍微修改下就行了 简单.
      

  7.   

    对了 补充一句:记得导入组建 JMail的  然后引入命名空间.
      

  8.   

    我用jmail 来发送电子邮件  但是出现这个错误“The message was undeliverable. All servers failed to receive the message ” 我怎么这么倒霉阿 ,什么错误都叫我遇见了,无奈了 还得请高人指点!!!
      谢谢!!!!!
      

  9.   

    这个偶用过好几次了,有的代码里面没有密码,smtp服务器的声明,要在web.config文件里面设置。在2005里面可以只写在cs文件里,不用更改web.config的设置。
      

  10.   

    最简单的:(测试通过)using System.Web.Mail;   
                        MailMessage em = new MailMessage(); em.To = “接收的邮箱”; em.From = "自己的邮箱"; em.Subject = 主题; em.Body = 内容; em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");   //basic authentication em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "用户名"); //set your username here em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码"); //set your password here SmtpMail.SmtpServer = "smtp.163.com";
    SmtpMail.Send(em);
      

  11.   

    推荐用JMAIL,下一个组件,再查查代码就搞定了。