C#make Gmail接受正文中的HTML

时间:2015-09-27 19:38:37

标签: c# html smtp

有人可以帮我这个吗?我有以下代码:

                    var fromAddress = new MailAddress("example@gmail.com", "Examplename");
                    var toAddress = new MailAddress(emailplain, nmreg1);
                    const string fromPassword = "example123";
                    const string subject = "example";
                    string body1 = "<h2>Text</h2>" + 
                        "<p>Text</p>" +
                        "<h3>text</h3>" +
                        "<p>___</p><img src=\"http://i.imgur.com/example.png\" alt=\"example\">";

                    var smtp = new SmtpClient
                    {
                        Host = "smtp.example.com",
                        Port = 1234,
                        EnableSsl = true,
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body1
                    })
                    {
                        smtp.Send(message);
                    }

如何更改此代码,以便Gmail正确显示HTML代码?

0 个答案:

没有答案