Why do I get “'property cannot be assigned” when sending an SMTP email?

前端 未结 17 2274
醉话见心
醉话见心 2020-11-22 05:50

I can\'t understand why this code is not working. I get an error saying property can not be assigned

MailMessage mail = new MailMessage();
SmtpClient client          


        
17条回答
  •  难免孤独
    2020-11-22 06:32

    MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text);
    mm.Subject = txtSubject.Text;
    mm.Body = txtBody.Text;
    if (fuAttachment.HasFile)//file upload select or not
    {
        string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
        mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
    }
    mm.IsBodyHtml = false;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = NetworkCred;
    smtp.Port = 587;
    smtp.Send(mm);
    Response.write("Send Mail");
    

    View Video: https://www.youtube.com/watch?v=bUUNv-19QAI

提交回复
热议问题