C# how to send an email containing a hyperlink using System.Net.Mail?

Asked

Viewed 376 times

0

I created a class for sending emails using the System.Net.Mail library.

To send the message format in HTML. The message I am sending is as follows::

<div style="display: block; margin-left: auto; margin-right: auto; width: 600px; font-family:Calibri,sans-serif;">
    <p>Olá Aluno,</p>
    <p>Recebemos uma solicitação para redefinir sua senha de acesso ao sistema MEUSISTEMA.</p>
    <p style="color:#1762aa; font-size:18px"><a href="www.MEUSISTEMA.com/ResetPassword?RecoverCode=893P7IN83FXO5UO2WASHTQI65LCP792O">Clique aqui para redefinir sua senha. </a></p><br>
    <p><strong style="font-size:18px">Importante: </strong>O link para redefinição de senha tem validade de 1 hora. Após este período será necessário gerar um novo link.</p>
</div>

Sending is being done correctly, however when I open the email to check the message that was sent, the hyperlink is strange:

Hello Student,

We received a request to reset your password to the MEUSISTEMA system.

[www.MEUSISTEMA.com/Resetpassword? Recovercode=V3A8AZ379JZIWSTPXZK6HT90Y8BIZYZ]Click here to reset your password.

Important: The password reset link is valid for 1 hour. After this period you will need to generate a new link.

What would be the way to correct that?

  • What is an email client? This seems to be a rendering rule on who is receiving and not a consequence of sending it.

  • I thought it might be the customer, I tested the upload to Hotmail and Gmail. The problem persisted. As the @Perozzo response the problem was the format of the hyperlink.

1 answer

0


Place the link as follows:

<a href=\"http://www.MEUSISTEMA.com/ResetPassword?RecoverCode=893P7IN83FXO5UO2WASHTQI65LCP792O\">Clique aqui para redefinir sua senha.</a>

Notice the counter bar added \ at the beginning and end of the link and the http:// at first.

And ensure that your object MailMessage has the following property defined for true:

IsBodyHTML = true;

Example:

MailMessage email = new MailMessage();
email.IsBodyHTML = true;
  • 1

    It worked perfectly. The email.Isbodyhtml property was already set to true. The problem was actually missing http://'

  • What are inverted bars for?

  • The backslashes would be in case you try to put a " inside a string that has already been opened with ", then the compiler would understand that you would be closing the string, but in your case you would just be opening the href tag with ". The backslash serves to say that the " is part of the string and that you do not want to terminate the string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.