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

前端 未结 17 2609
醉话见心
醉话见心 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:41

    This is how it works for me. Hope you find it useful

    MailMessage objeto_mail = new MailMessage();
    SmtpClient client = new SmtpClient();
    client.Port = 25;
    client.Host = "smtp.internal.mycompany.com";
    client.Timeout = 10000;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("user", "Password");
    objeto_mail.From = new MailAddress("from@server.com");
    objeto_mail.To.Add(new MailAddress("to@server.com"));
    objeto_mail.Subject = "Password Recover";
    objeto_mail.Body = "Message";
    client.Send(objeto_mail);
    

提交回复
热议问题