简体   繁体   English

发送邮件时无法在锚标记中发送 href (GMAIL)

[英]unable to send href in anchor tag while sending a mail (GMAIL)

Explanation : I am trying to send href in html anchor tag in email from MVC controller.说明:我试图在来自 MVC 控制器的电子邮件中发送html anchor tag中的href It is working fine with yohoo mail and also with outlook but only getting issue with Gmail .它与yohoo邮件和outlook一起工作正常,但只有Gmail问题。 Don't know why but when I am sending email to Gmail ID than html anchor tag just remove the href attribute from anchor tag.不知道为什么,但是当我向 Gmail ID 发送电子邮件而不是html anchor tag只需从锚标记中删除 href 属性即可。 It is Happening only with gmail ID.它只发生在 gmail ID 上。 I am using html template to send email.我正在使用 html 模板发送电子邮件。

E-Mail Html Template电子邮件 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>

Generating E-Mail Body Code生成电子邮件正文代码

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;
}

Only in Gmail don't know why href is removed automatically.仅在 Gmail 中不知道为什么会自动删除 href。 I traced above code it seems fine but unable to traced it out why issue with gmail.我跟踪了上面的代码,它看起来不错,但无法找出 gmail 出现问题的原因。 So please make me correct where I am doing mistake.所以请让我纠正我做错的地方。 If more information required than please let me know I will update question.如果需要更多信息,请告诉我,我会更新问题。

It is possible that Gmail itself filters the message and removes undesired html tags due to user security.出于用户安全的考虑,Gmail 本身可能会过滤邮件并删除不需要的 html 标签。 A suspicious url in the message might be deliberately removed by Google before the recepient receives it. Google 可能会在收件人收到邮件之前故意删除邮件中的可疑网址。 Perhaps you need to check how to comply with Gmail content policies, unfortunately I cannot point you to any appropriate resources about that.也许您需要检查如何遵守 Gmail 内容政策,不幸的是,我无法为您提供任何相关资源。

The only workaround I can think of is reformatting the link tag.我能想到的唯一解决方法是重新格式化链接标签。 It should either contain text with the link itself (so the receiver sees what is the actual link) and be made to open in new window/tab (by using "target="_blank" ).它应该包含带有链接本身的文本(以便接收者看到实际链接是什么)并在新窗口/选项卡中打开(通过使用 "target="_blank" )。

For example javascript events assigned to a link makes it suspicious, or might trigger the spam filter - in an email links should point to resources directly.例如,分配给链接的 javascript 事件使其变得可疑,或者可能触发垃圾邮件过滤器 - 电子邮件中的链接应直接指向资源。 A link name different from the target, or not suggesting what is going to happen if you follow it could also raise some alarms.与目标不同的链接名称,或者不暗示如果您遵循它会发生什么也可能引发一些警报。

I suppose Google might be using part of, or their entire link ranking algorithm which is also employed by their search engine (PageRank).我想谷歌可能正在使用他们的搜索引擎 (PageRank) 也采用的部分或整个链接排名算法。 Someone familiar with SEO could help you further in making your links more appealing to google's search engine, and that could result in Gmail not to treat them the way you experience.熟悉 SEO 的人可以帮助您进一步使您的链接对 google 的搜索引擎更具吸引力,这可能会导致 Gmail 不会按照您的体验方式对待它们。

Simply add the http:// in front of your link because Google removes the suspicious IP, port number and link tag.只需在链接前添加http:// ,因为 Google 会删除可疑的 IP、端口号和链接标签。 Your link should use a proper protocol.您的链接应该使用正确的协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM