想写个简单的页面,有标题,内容,然后发送按钮发送到指定的邮箱即可
但发送的邮件服务器要求发送端认证的
代码中如何设置发送端认证这个属性
望实现过的大侠指点一下
谢谢

解决方案 »

  1.   


     private void btnNet_Click(object sender, EventArgs e)
            {
                try
                {
                    MailAddress from = new MailAddress(txtFrom.Text);
                    MailAddress to = new MailAddress(txtTo.Text);
                    MailAddress cc = new MailAddress(txtCC.Text);
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
                    message.CC.Add(cc);
                    message.Subject = txtSubject.Text;
                    message.SubjectEncoding = Encoding.UTF8;
                    message.Body = txtBody.Text;
                    message.BodyEncoding = Encoding.UTF8;
                    message.IsBodyHtml = (txtBodyFormat.Text.Trim() == "Text" ? false : true);                SmtpClient client = new SmtpClient(txtServer.Text);
                    client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    if (this.txtUser.Text != "" && this.txtPassword.Text != "")
                    {
                        client.Credentials = new System.Net.NetworkCredential(this.txtUser.Text, this.txtPassword.Text);--賬號,密碼
                    }
                    client.Send(message);
                    MessageBox.Show("Mail Sent");            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
      

  2.   

    按照zhangandli的代码运行后得到“身份验证失败”的提示
    该如何解决,是哪里出的问题
      

  3.   

        public void SendMail()
        {          
            MailMessage mymail = new MailMessage();
            string strmailserver = ConfigurationSettings.AppSettings["MailIP"].ToString();  //邮箱服务器
            SmtpMail.SmtpServer = strmailserver;        bool flag = false;
         
       
                    mymail.From = "***";
                    mymail.To = "***";
                    mymail.Subject = "***";
                    mymail.Body = "***";
                     flag = ISsendMail(mymail);
                }
            }
            if (flag == true)
            {
                Response.Write("<script>alert('邮件发送成功!')</script>");
            }
            else
            {
                Response.Write("<script>alert('邮件发送失败!无法找到Email地址!')</script>");
            }
        }    public bool ISsendMail(MailMessage MailMes)
        {
            string strIsSend = ConfigurationSettings.AppSettings["IsSendMail"].ToString();
            if (strIsSend == "true")
            {
                try
                {
                    SmtpMail.Send(MailMes);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
           
        }