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

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

    send email by smtp

    public void EmailSend(string subject, string host, string from, string to, string body, int port, string username, string password, bool enableSsl)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient smtpServer = new SmtpClient(host);
                mail.Subject = subject;
                mail.From = new MailAddress(from);
                mail.To.Add(to);
                mail.Body = body;
                smtpServer.Port = port;
                smtpServer.Credentials = new NetworkCredential(username, password);
                smtpServer.EnableSsl = enableSsl;
                smtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    

提交回复
热议问题