【发布时间】:2016-06-08 12:13:38
【问题描述】:
说明:我正在尝试从 MVC 控制器通过电子邮件在 html anchor tag 中发送 href。它与yohoo 邮件和outlook 一起工作正常,但只有Gmail 出现问题。不知道为什么,但是当我向 Gmail ID 发送电子邮件而不是 html anchor tag 时,只需从锚标记中删除 href 属性。它只发生在 gmail ID 上。我正在使用 html 模板发送电子邮件。
电子邮件 HTML 模板
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<center>
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable">
<tr>
<td align="center" valign="top" id="bodyCell">
<table border="0" cellpadding="0" cellspacing="0" id="templateContainer">
<tr>
<td style="text-align:center;vertical-align:top;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateHeader">
<tr>
<td class="headerContent" style="text-align:center;vertical-align:top;">
<img src="cid:logo" style="max-width:600px;" id="headerImage" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align:center;vertical-align:top;">
<table style="border:0;width:100%;" cellpadding="0" cellspacing="0" id="templateBody">
<tr>
<td valign="top" class="bodyContent" mc:edit="body_content">
<h1>Dear @ReceiverFirstNAME@,</h1>
<p style="text-align:justify;">Please click on below URL to download your backup file for @CompanyName@</p>
<p><a href="@BackupURL@" style="color:blue">Download</a></p>
<p style="text-align:justify;">Download link will be expire after 24 Hours.</p>
<br /> ********************************************************************************************
<br /> This is a system generated mail, so please do not reply to this email id.
<br /> ********************************************************************************************
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align:center;vertical-align:top;">
<table style="border:0;width:100%;" cellpadding="0" cellspacing="0" id="templateFooter">
<tr>
<td class="footerContent" style="padding-top:0;vertical-align:top;text-align:center;">
<em>Copyright © H2eFile 2015. All rights reserved.</em>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
生成电子邮件正文代码
private AlternateView GenerateBodyTag(string companyName, string companyCode, string firstName, string lastName, string url, string logo) {
StreamReader readtemplte = new StreamReader(Server.MapPath(@ "\\MailResource/ApplicationBackup.html"));
string mailmsg = readtemplte.ReadToEnd();
mailmsg = mailmsg.Replace("@ReceiverFirstNAME@", firstName + " " + lastName);
mailmsg = mailmsg.Replace("@CompanyName@", companyName);
mailmsg = mailmsg.Replace("@BackupURL@", url);
byte[] data = System.Convert.FromBase64String(logo);
MemoryStream ms = new MemoryStream(data);
LinkedResource linkLogo = new LinkedResource(ms);
linkLogo.ContentId = "logo";
AlternateView objAv = AlternateView.CreateAlternateViewFromString(mailmsg, null, MediaTypeNames.Text.Html);
objAv.LinkedResources.Add(linkLogo);
return objAv;
}
只有在 Gmail 中不知道为什么自动删除 href。我追踪了上面的代码,它看起来很好,但无法追踪为什么 gmail 有问题。所以请让我纠正我做错的地方。如果需要更多信息,请告诉我,我会更新问题。
【问题讨论】:
-
出于用户安全考虑,Gmail 本身可能会过滤邮件并删除不需要的 html 标签。 Google 可能会在收件人收到邮件之前故意删除邮件中的可疑网址。也许您需要检查如何遵守 Gmail 内容政策,很遗憾,我无法为您提供任何相关资源。
-
@IvayloSlavov 感谢您分享您的知识。但可能还有其他方式。
-
查看我的答案以了解详细信息,其中包括我之前的评论和潜在的建议
标签: c# asp.net-mvc email gmail