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

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

    Finally got working :)

    using System.Net.Mail;
    using System.Text;
    
    ...
    
    // Command line argument must the the SMTP host.
    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("user@gmail.com","password");
    
    MailMessage mm = new MailMessage("donotreply@domain.com", "sendtomyemail@domain.co.uk", "test", "test");
    mm.BodyEncoding = UTF8Encoding.UTF8;
    mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    
    client.Send(mm);
    

    sorry about poor spelling before

提交回复
热议问题