自己学习C#,写了电子邮件发送的代码,可是来是没对。不晓得怎么搞的。请高人写一段过来学习学习。谢谢!

解决方案 »

  1.   

    http://www.cnblogs.com/pipizhu/archive/2009/09/28/1575851.html
      

  2.   

    http://blog.sina.com.cn/s/blog_56e2f4250100bvxh.html
    http://blog.csdn.net/hx_xiaoyi/archive/2010/01/05/5137186.aspx
      

  3.   

    在.Net FrameWork中System.Web.Mail的命名空间提供了类SmtpMail,用于发送电子邮件,以下是我发送邮件的代码:MailMessage mm=new MailMessage();
       
       mm.From="[email protected]";
       mm.To="[email protected]";
       mm.Subject="收到了回个话";
       mm.Body="为什么Smtp类的Server属性不提供口令验证";
       mm.Attachments.Add(new MailAttachment("c:\\test.txt"));
       //Attachments实现IList接口,可以添加多个附件
          
       SmtpMail.SmtpServer="webmail.careland.com.cn";
       //设置发送邮件的Smtp服务器,目前没有提供需要身份验证的服务器的登陆方法
       //比如163.net,163.com都不行,目前我的是我公司的SMTP服务器
       //看看大伙有没有更好的办法
       SmtpMail.Send(mm);
          
       MessageBox.Show("OK");
      

  4.   

    把这个改下下就可以了:
            #region "邮件发送"
            /// <summary>
            /// 发送邮件
            /// </summary>
            /// <param name="strto">接收邮件地址</param>
            /// <param name="strSubject">主题</param>
            /// <param name="strBody">内容</param>
            public static void SendSMTPEMail(string strto, string strSubject, string strBody)
            {
                string SMTPHost = ConfigurationManager.AppSettings["SMTPHost"];
                string SMTPPort = ConfigurationManager.AppSettings["SMTPPort"];
                string SMTPUser = ConfigurationManager.AppSettings["SMTPUser"];
                string SMTPPassword = ConfigurationManager.AppSettings["SMTPPassword"];
                string MailFrom = ConfigurationManager.AppSettings["MailFrom"];
                string MailSubject = ConfigurationManager.AppSettings["MailSubject"];            SmtpClient client = new SmtpClient(SMTPHost);
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;            MailMessage message = new MailMessage(SMTPUser, strto, strSubject, strBody);
                message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
                message.IsBodyHtml = true;            client.Send(message);
            }
            #endregion
      

  5.   

    还可以。虽然提示过时了。但不影响使用。using System.Web.Mail;
      
    MailMessage mail = new MailMessage();
                    mail.BodyFormat = MailFormat.Html;
                    mail.To =“接收人地址”;
                    mail.Subject = “标题”;                mail.Body = string.Format(MailHtmlBody, mailContent);                mail.BodyEncoding = Encoding.GetEncoding("GB2312");
                    
                    mail.From = “发送人地址”;
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ht["username"].ToString()); //set your username here
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ht["password"].ToString()); //set your password here
                    SmtpMail.SmtpServer = "邮件服务器IP";
                    SmtpMail.Send(mail);