2

I'm trying to send transaction emails from my website using the MailKit library but I can't make the html render an anchor tag. In fact I'm not sure that any of the html is being rendered. Any ideas what's wrong? My code is below.

var message = new MimeMessage();
        message.From.Add(new MailboxAddress("Eternal Meta", "eternal.meta.transactions@gmail.com"));
        message.To.Add(new MailboxAddress(user.Username, user.Email));
        message.Subject = "Eternal Meta - Registration";

        var builder = new BodyBuilder();

        builder.HtmlBody = "<p>Use the link below to activate your account</p><br><a href=" + "Localhost:49288/Users/Activate?userId=" + user.UserID + "&token=" + user.Token + ">Click Me</a>";

        message.Body = builder.ToMessageBody();

        using (var client = new SmtpClient())
        {
            client.Connect("smtp.gmail.com", 587, false);
            client.Authenticate("eternal.meta.transactions@gmail.com", "password");

            client.Send(message);

            client.Disconnect(true);
        }
Jessie Cryer
  • 159
  • 2
  • 9

1 Answers1

0

Use a fully qualified URL for the "href" attribute (like https://[...]).

The mail client can parse the HTML inside your message and most probably the "href" attribute gets removed as the URL is considered relative.

  • The app is only being hosted locally so I don't have a fully qualified URL to direct the link to – Jessie Cryer Dec 12 '17 at 19:48
  • Doesn't matter, just prepend the protocol to your URL (like `http://localhost/...` - "localhost" will act as your domain for 127.0.0.1 anyway) – gabriel0x62 Dec 12 '17 at 20:02