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

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

    This just worked for me as of March 2017. Started with solution from above "Finally got working :)" which didn't work at first.

    SmtpClient client = new SmtpClient();
    client.Port =  587;
    client.Host = "smtp.gmail.com";
    client.EnableSsl = true;
    client.Timeout = 10000;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("@gmail.com", "");
    MailMessage mm = new MailMessage(from_addr_text, to_addr_text, msg_subject, msg_body);
    mm.BodyEncoding = UTF8Encoding.UTF8;
    mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    
    client.Send(mm);
    

提交回复
热议问题