Enrique Moreno Tent
Enrique Moreno Tent

Reputation: 25307

link anchors in HTML email

I am trying to make a newsletter email with an idnex that has links to different anchors in the mail, but so far, it doesn't seem to work in any client. This is the code:

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

What?s even weirder, in GMAIL my ID tag disappears and my name tag gets some sort of weird prefix, like "124335132_anchor1". What could I do?

Upvotes: 4

Views: 10907

Answers (4)

Stavros
Stavros

Reputation: 6140

To work with outlook 2010, it has to be like that:

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

Upvotes: 0

Ryane
Ryane

Reputation: 49

you know how usually you have the string

<div id="boom">...

and you want to anchor link to that from somewhere else, you would enter

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

so now you would use a name tag in addition to your destination.

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

Viola! anchor link in html email.

Upvotes: 4

Hendra
Hendra

Reputation: 53

not sure i'm getting what you mean.. but, it looks like you wanted to send MIMEBody as an email content, so the email looks like an html format.. if it the case, here is some piece from my java code:

@Override
    public void coba() {
        try {

            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject("Whatever");
            message.setRecipient(RecipientType.TO, new InternetAddress("[email protected]", "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();
        }
    }

i send an email with html format, here is screen shot the message content on gmail

here is the screen shot

hopefully it have any use for you..

Upvotes: -2

Quentin
Quentin

Reputation: 944299

Email clients aren't web browsers or designed to be. They leave off vast swathes of things you are likely to consider "pretty basic".

Make all links absolute and plan for them to open in a web browser.

Upvotes: 2

Related Questions