c# - 从 C# 发送 html 电子邮件

标签 c# html email

我正在尝试向 gmail 帐户发送 html 电子邮件,但出于某种原因,Google 正在从我的电子邮件中删除 html。当我发送到其他帐户(非 Gmail 帐户)时,Html 会被保留,所以我知道我的 html 是正确的。

下面是我的做法:

  1. 我有一个 aspx 页面,用作电子邮件模板。
  2. 我从 Web 服务中的 aspx 页面抓取 html(用 C# 完成)
  3. 通过 Web 服务中的 C# 代码动态填充非静态内容。
  4. 将其作为电子邮件正文发送。

有没有人碰巧知道为什么 gmail 会删除 html? 提前致谢。

最佳答案

您需要确保在 MailMessage 上将 IsBodyHtml 属性设置为 true:

var message = new MailMessage();
message.IsBodyHtml = true;
// Fill and send message here

查看 MSDN 引用以获取更多信息:

System.Net.Mail.MailMessage Members

关于c# - 从 C# 发送 html 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3430798/

相关文章:

c# - 从子控件中检测表单移动事件

html - 如何去除视差内部滚动条

c# - 未发布 Excel Interop 对象

c# - HttpWebRequest 在 mono 和 .net 中的实现方式不同吗?

javascript - 如何自定义 Bootstrap JS Popover

android - 使用 Html.fromHtml(message) 时未定义的构造函数 BasicNameValuePair(String, Spanned)

ASP.NET 电子邮件验证器正则表达式

wordpress - MX 记录 mailgun 和 gsuite/gmail。在 mailgun 上使用子域 = 在我的 WP 主机(siteground)上添加子域?

c# - 在 VS 2008 中运行单元测试项目时出现 DisconnectedContext 错误

html - 通过调整页面大小扩展导航栏 Twitter Bootstrap