在自己写的程序中,要把一些信息发送到邮箱中....

解决方案 »

  1.   

    public void Email()//发送邮件
        {        string UserEmail = Request.QueryString["Email"].ToString().Trim().Replace("\'", "\'\'");
            System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();        myMail = new System.Net.Mail.MailMessage("[email protected]", UserEmail);//这里使用的163油箱
            myMail.Subject = "!";//邮件发送标题
            myMail.Body = "!";//邮件发送内容        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.163.com", 25);
            client.Credentials = new System.Net.NetworkCredential("XXXXX", "密码");//这里的XXXXX是用户名
            client.Send(myMail);    }
      

  2.   

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="tomail">要发送的邮件地址</param>
        /// <param name="subject">主题</param>
        /// <param name="body">内容</param>
        private void sendMails(string tomail, string subject, string body)
        {
            string email_from = System.Configuration.ConfigurationManager.AppSettings["email_from"].ToString();
            string email_display_name = System.Configuration.ConfigurationManager.AppSettings["email_display_name"].ToString();
            string email_client = System.Configuration.ConfigurationManager.AppSettings["email_client"].ToString();
            string username = System.Configuration.ConfigurationManager.AppSettings["username"].ToString();
            string password = System.Configuration.ConfigurationManager.AppSettings["password"].ToString();        //Send   mail   use   smtp.163.com   server....
            MailMessage objMailMessage;
            objMailMessage = new MailMessage();
            objMailMessage.From = new MailAddress(email_from, email_display_name);
            objMailMessage.To.Add(tomail);
            objMailMessage.IsBodyHtml = true;
            objMailMessage.Subject = subject;
            objMailMessage.Body = body;
            
            //Attachment mailattent = new Attachment(fileroad);//添加一个附件
            //objMailMessage.Attachments.Add(mailattent);        SmtpClient sclient = new SmtpClient(email_client);
            sclient.Credentials = new System.Net.NetworkCredential(username,password);
            try
            {
                sclient.Send(objMailMessage);
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);
            }
        }