aryanm
aryanm

Reputation: 1259

Send hyperlinks in email body using AWS SES in Node.js

I am using the AWS.SES (simple email service) kit in my Node.js Lambda function.

I can send emails just fine, but if I try to include a simple hyperlink in the email, it displays just plain text instead of a clickable hyperlink.

This is the code I'm using to send the email.

function sendVerificationEmail(userinfo, vKey, after) {
    var params = {
        Destination: {
            ToAddresses: [userinfo.email]
        },
        Message: {
            Body: {
                Html: {
                    Charset: "UTF-8",
                    Data: "<html><body>Hey " + userinfo.name + ", <a href='https://s3.amazonaws.com/xxxx/xxxx.html?v=" + vKey + "'>Click here to validate this email address.</a></body></html>"
                },
                Text: {
                    Charset: "UTF-8",
                    Data: "Hey " + userinfo.name + ",\n\nOpen this link in your web browser to validate this email address:\nhttps://s3.amazonaws.com/xxxx/xxxx.html?v=" + vKey
                }

            },

            Subject: { Data: "Scheduler - Verify Your Email Address" }
        },
        Source: "[email protected]"
    };

     ses.sendEmail(params, function(err, data) {
        after(err, data);
    });
}

As you can see in the HTML, I have included an <a> tag. However, The link is displayed as unclickable plaintext in the email.

Edit: Gmail's "Show Original" feature displays the following:

Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hey TestName,

Open this link in your web browser to validate this email address:
https://s3.amazonaws.com/xxxx/xxxx.html?v=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
---------------------------------------------------
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<html><body>Hey TestName, <a href='https://s3.amazonaws.com/xxxx/xxxx.html?v=xxxxxxxxxxxxx'>Click here to validate this email address.</a></body></html>

Upvotes: 1

Views: 3087

Answers (2)

vivek sharma
vivek sharma

Reputation: 369

In my case it was occuring only when I added dynamic content inside href attribute as shown below, token is dynamic :

"<a href=`https://example.com/verify/${token}`>Click Here</a>"

As you can see the anchor tag is enclosed in double quotes so I simlpy changed it to backtick (rendered token variable using template literal) as shown below, :

`<a href="https://example.com/verify/${token}">Click Here</a>`

hope this format resolves the issue for future readers

Upvotes: 0

Pranav Joglekar
Pranav Joglekar

Reputation: 747

If you observe the raw email contents you will observe that it misses the = sign between in href=<link>. This is because the '=' symbol is used as a line break in the smtp protocol messages(I think). Anyways, the way to fix this is to add the unicode for the '=' symbol which is U+003D Try this:-

<a href=3D"${link}">${text}</a>

The =3D is interpreted as the = symbol and the content encoding is done correctly.

Upvotes: 2

Related Questions