Send HTML email via C# with SmtpClient

后端 未结 6 708
野趣味
野趣味 2020-11-28 08:43

How do I send an HTML email? I use the code in this answer to send emails with SmtpClient, but they\'re always plain text, so the link in the example message be

6条回答
  •  误落风尘
    2020-11-28 08:55

    i have an idea , you can add a check box to your project for sending email as html as an option for user , and add this code to enable it :

             MailMessage mail = new MailMessage(from, to, subject, message);
    
             if(checkBox1.CheckState == CheckState.Checked )
               {
                   mail.IsBodyHtml = true;
               }
    
             SmtpClient client = new SmtpClient("localhost");
    
             client.Send(mail);
    

提交回复
热议问题