我需要格式化从我的Windows Form C#应用程序发送的电子邮件

时间:2021-01-21 07:36:33

When a user clicks "email" button it sends everything in my form. I need to add bold and italic to the form. here is the button click code:

当用户点击“电子邮件”按钮时,它会发送我表单中的所有内容。我需要在表单中添加粗体和斜体。这是按钮点击代码:

*For those looking to use this code, I have placed everything that will need changed in all caps, any questions on the code please ask.

*对于那些希望使用此代码的人,我已将所有需要更改的内容放在所有大写字母中,有关代码的任何问题请询问。

Here is the code behind:

这是后面的代码:

private void button1_Click(object sender, EventArgs e)
    {

            MailMessage msg = new MailMessage(); 
            msg.To.Add("SENT FROM EMAIL");               
            MailAddress address = new MailAddress("WHO THE FORM GETS EMAIL   
 FROM");
            msg.From = address;            
            msg.Subject = "Daily Checklist for " + check_Date_TextBox.Text;
            msg.IsBodyHtml = true;          

I want to format this line

我想格式化这一行

msg.Body = "Check Date: " + <b>check_Date_TextBox.Text</b> + Environment.NewLine +

It has been recomdnded to put the html formatting in the code above but it gives me an error

它已被重新建议将html格式放在上面的代码中,但它给了我一个错误

        SmtpClient client = new SmtpClient("SMTP CLIENT, PORT);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;   
        client.EnableSsl = false;                               
            NetworkCredential credentials = new NetworkCredential("SENT FROM 
EMAIL", "PASSWORD");
            client.Credentials = credentials;


            client.Send(msg);
        }

1 个解决方案

#1


In the string body you are creating give the html tags such as <b>, <i> where ever you needed and before sending add the below code also

在你正在创建的字符串正文中给出html标记,例如,,无论你需要什么,在发送之前还要添加以下代码

msg.IsBodyHtml = true;

hope it will help

希望它会有所帮助

#1


In the string body you are creating give the html tags such as <b>, <i> where ever you needed and before sending add the below code also

在你正在创建的字符串正文中给出html标记,例如,,无论你需要什么,在发送之前还要添加以下代码

msg.IsBodyHtml = true;

hope it will help

希望它会有所帮助