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

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

     //Hope you find it useful, it contain too many things
    
        string smtpAddress = "smtp.xyz.com";
        int portNumber = 587;
        bool enableSSL = true;
        string m_userName = "support@xyz.com";
        string m_UserpassWord = "56436578";
    
        public void SendEmail(Customer _customers)
        {
            string emailID = gghdgfh@gmail.com;
            string userName = DemoUser;
    
            string emailFrom = "qwerty@gmail.com";
            string password = "qwerty";
            string emailTo = emailID;
    
            // Here you can put subject of the mail
            string subject = "Registration";
            // Body of the mail
            string body = "
    "; body += "

    Aspen Reporting Tool

    "; body += "
    "; body += "Dear " + userName + ","; body += "
    "; body += "

    "; body += "Thank you for registering

    "; body += "

    Click HereTo finalize the registration process

    "; body += "
    "; body += "Thanks,"; body += "
    "; body += "The Team"; body += "
    "; // this is done using using System.Net.Mail; & using System.Net; using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(emailFrom); mail.To.Add(emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; // Can set to false, if you are sending pure text. using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } } }

提交回复
热议问题