/// <summary>
        /// 发送EMAIL
        /// </summary>
        /// <param name="sRecipientEmail">收件人地址</param>
        /// <param name="sSubject">主题</param>
        /// <param name="sMessage">内容</param>
        /// <returns>发送是否成功</returns>
        public static bool SendMail(string sRecipientEmail, string sSubject, string sMessage,string sSendName)
        {            //邮件对象
            MailMessage emailMessage;            //smtp客户端对象            SmtpClient client;            // 初始化邮件对象            if (string.IsNullOrEmpty(sSendName))
            {
                sSendName = "客户服务中心";
            }
            
            //String sSenderEmail = ConfigurationManager.AppSettings["EmailAddress"];
            String sSenderEmail = ""+sSendName+"<" + ConfigurationManager.AppSettings["EmailAddress"] + ">";            emailMessage = new MailMessage(sSenderEmail, sRecipientEmail, sSubject, sMessage);
            emailMessage.IsBodyHtml = true;
            emailMessage.SubjectEncoding = System.Text.Encoding.Default;
            emailMessage.BodyEncoding = System.Text.Encoding.Default;
            //加入
            emailMessage.Headers.Add("X-Priority", "3");
            emailMessage.Headers.Add("X-MSMail-Priority", "Normal");
            emailMessage.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
            emailMessage.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
            emailMessage.Headers.Add("ReturnReceipt", "1");            //邮件发送客户端
            client = new SmtpClient();            //邮件服务器及帐户信息
            client.Host = ConfigurationManager.AppSettings["EmailServer"];
            //client.Host = "smtp.163.com";
            
            //client.Port = 465;
            //client.EnableSsl = true;
            System.Net.NetworkCredential Credential = new System.Net.NetworkCredential();
          
            Credential.UserName = ConfigurationManager.AppSettings["EmailUserName"];
            Credential.Password = ConfigurationManager.AppSettings["EmailPassword"];  
            //TODO: 需要更新该密码到web.config
            client.Credentials = Credential;            try
            {
                client.Send(emailMessage);
            }
            catch (Exception e)
            {
                //错误处理待定
                string sMsg = e.Message;
                return false;
            }
            return true;        }

解决方案 »

  1.   

       private bool SendMail(string toMail, string subject, string body)
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(Application.StartupPath.ToString()+"\\data.xml");
                    string fromMail = ds.Tables[0].Rows[0]["frommail"].ToString();
                    MailMessage myMail = new MailMessage();
                    myMail.From = fromMail;
                    myMail.To = toMail;
                    //myMail.Cc = ccMail;
                    //myMail.Bcc = bccMail;
                    myMail.Subject = subject;
                    myMail.Body = body;
                    myMail.BodyFormat = MailFormat.Html;                //附件
                    string ServerFileName = "";
                    //if (this.upfile.PostedFile.ContentLength != 0)
                    //{
                    //    string upFileName = this.upfile.PostedFile.FileName;
                    //    string[] strTemp = upFileName.Split('.');
                    //    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                    //    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                    //    this.upfile.PostedFile.SaveAs(ServerFileName);
                    //    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                    //}
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ds.Tables[0].Rows[0]["username"].ToString()); //发送方邮件帐户
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ds.Tables[0].Rows[0]["password"].ToString()); //发送方邮件密码                SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                    SmtpMail.Send(myMail);                return true;
                }
                catch
                {
                    return false;
                }
            }
    自带的很好用的
      

  2.   

    楼上的人太惯了,所以很多人都懒了----------------------------------------------------------------------------------------
    欢迎访问我的新站:http://www.FavNet.cn —— 专勤致精 想您所思 专业IT技术服务
    展示技术实力,寻求合作伙伴、合作项目中……
      

  3.   

    Dim message As new Mail.MailMessage message.From = "[email protected]" message.To = "[email protected]" message.Subject = "测试" message.Body = "内容" Mail.SmtpMail.SmtpServer = "localhost" Mail.SmtpMail.Send(message) 
    参考
      

  4.   

    private static string SendMail(string MailFrom, string MailTo, string MailTocc, string Subject, string Content, string PRI, string MailServer)
    {
    if ((((MailFrom != null) && (MailFrom.Trim() != "")) && ((MailTo != null) && (MailTo.Trim() != ""))) && (((Subject != null) && (Subject.Trim() != "")) && ((MailServer != null) && (MailServer.Trim() != ""))))
    {
    try
    {
    MailMessage message = new MailMessage();
    message.From = MailFrom;
    message.To = MailTo;
    if ((MailTocc != null) && (MailTocc.Trim() != ""))
    {
    message.Cc = MailTocc;
    }
    message.Subject = Subject;
    message.Body = Content;
    SmtpMail.SmtpServer = MailServer.Trim();
    message.BodyFormat = MailFormat.Html;
    if ((PRI != null) && (PRI.Trim() != "0"))
    {
    if (PRI == "1")
    {
    message.Priority = MailPriority.Normal;
    }
    else
    {
    message.Priority = MailPriority.Low;
    }
    }
    else
    {
    message.Priority = MailPriority.High;
    }
    SmtpMail.Send(message);
    return "1";
    }
    catch (Exception exception)
    {
    return exception.Message;
    }
    }
    return "Email必要参数缺失";
    }