【问题标题】:unable to send href in anchor tag while sending a mail (GMAIL)发送邮件时无法在锚标记中发送 href (GMAIL)
【发布时间】: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


【解决方案1】:

出于用户安全考虑,Gmail 本身可能会过滤邮件并删除不需要的 html 标记。 Google 可能会在收件人收到邮件之前故意删除邮件中的可疑网址。也许您需要检查如何遵守 Gmail 内容政策,遗憾的是我无法为您提供任何相关资源。

我能想到的唯一解决方法是重新格式化链接标签。它应该包含带有链接本身的文本(以便接收者看到实际链接是什么)并在新窗口/标签中打开(通过使用 "target="_blank" )。

例如,分配给链接的 javascript 事件使其可疑,或者可能触发垃圾邮件过滤器 - 电子邮件中的链接应直接指向资源。与目标不同的链接名称,或者不暗示如果您关注它会发生什么,也可能会引发一些警报。

我想 Google 可能正在使用他们的搜索引擎 (PageRank) 也使用的部分或全部链接排名算法。熟悉 SEO 的人可以帮助您进一步使您的链接对 google 的搜索引擎更具吸引力,这可能导致 Gmail 不以您的体验方式对待它们。

【讨论】:

  • 不工作我试图替换如下 '

    Download

    ' 不只是像这样转换 'Download'跨度>
  • 将那个 url 标签添加到您的问题中是一件好事,我的错误是我之前没有要求。避免在电子邮件消息中对 onclick 事件进行 javascript 调用。当然,Goggle 有理由删除或阻止此类链接。
  • 我在删除 javascript 和 onclick 后检查过,但仍然无法正常工作。
【解决方案2】:

只需在链接前添加http://,因为 Google 会删除可疑 IP、端口号和链接标签。 您的链接应使用正确的协议。

【讨论】:

  • 这并不能解决问题。 Google 甚至会删除 https:// 链接。
猜你喜欢
  • 1970-01-01
  • 2021-01-27
  • 2018-12-14
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-25
  • 2013-10-28
相关资源
最近更新 更多