链接HTML电子邮件中的锚点

时间:2011-03-28 10:59:46

标签: html email

嘿伙计们。我试图制作一个带有idnex的电子邮件电子邮件,该电子邮件链接到邮件中的不同锚点,但到目前为止,它似乎不适用于任何客户端。这是代码:

<ul style="list-style: none; margin: 0px; padding: 0px; ">
  <li><a href="#anchor1">Sehen wir uns auf der ISH?</a></li>
  <li><a href="#anchor1">Sehen wir uns auf der ISH?</a></li>
  <li><a href="#anchor1">Sehen wir uns auf der ISH?</a></li>
  <li><a href="#anchor1">Sehen wir uns auf der ISH?</a></li>
  <li><a href="#anchor1">Sehen wir uns auf der ISH?</a></li>
</ul>

...

<a name="anchor1" id="anchor1">foo</a>
什么?甚至更奇怪,在GMAIL中我的ID标签消失了,我的名字标签得到某种奇怪的前缀,比如“124335132_anchor1”。我该怎么办?

4 个答案:

答案 0 :(得分:2)

电子邮件客户端不是网络浏览器或设计为。他们留下了大量你可能认为“非常基本”的东西。

使所有链接都是绝对的,并计划在网络浏览器中打开它们。

答案 1 :(得分:2)

你知道你有多少字符串

<div id="boom">...

并且您想要从其他地方锚定指向该链接的链接,您可以输入

<a href="#boom"></a>

所以现在除了目的地之外还要使用名称标签。

<a name="boom"></a><div id="boom">...

中提琴! html电子邮件中的锚链接。

答案 2 :(得分:0)

要使用Outlook 2010,它必须是这样的:

<a href="#section1">Jump to section!</a>
<p>A bunch of content</p>
<a name="section1">An anchor!</a>

答案 3 :(得分:-1)

不确定我的意思是什么..但是,看起来你想将MIMEBody作为电子邮件内容发送,所以电子邮件看起来像一个html格式..如果是这样的话,这里有一些来自我的java代码:

@Override
    public void coba() {
        try {

            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject("Whatever");
            message.setRecipient(RecipientType.TO, new InternetAddress("SomeEmail@email.com", "SomeName Name"));

            //
            // This HTML mail have to 2 part, the BODY and the embedded image
            //
            MimeMultipart multipart = new MimeMultipart("related");

            // first part  (the html)
            BodyPart messageBodyPart = new MimeBodyPart();
            String htmlText = "<div style=\"width:800px; background-color:#525252\"><h1>Header</h1></div><br /><div style=\"width:200px; background-color:#ff0000; float: left\"><h3>Navigation Panel</h3><ul><li>link <a href=\"http://google.com\">here</a></li><li>link <a href=\"http://google.com\">here</a></li></ul></div><div style=\"width:600px; background-color:#727272; float: left\"><h3>Content</h3><p>blabla blabla blabla blabla blabla</p><br /><img src=\"cid:image\" /></div>";
            messageBodyPart.setContent(htmlText, "text/html");

            // add it
            multipart.addBodyPart(messageBodyPart);

            // second part (the image)
            messageBodyPart = new MimeBodyPart();
            DataSource fds = new FileDataSource("C:/img/lion.JPG");
            messageBodyPart.setDataHandler(new DataHandler(fds));
            messageBodyPart.setHeader("Content-ID","<image>");

            // add it
            multipart.addBodyPart(messageBodyPart);

            // put everything together
            message.setContent(multipart);

            Transport.send(message);

            //System.out.println("Successfully Send Email(" + subject + ") to " + emailAddress);

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

我发送一封html格式的电子邮件,这里是屏幕截图gmail上的消息内容

here is the screen shot

希望它对你有用..