Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to send an particular page url link(local host login page) to an email address(typed in textbox).If user clicks the submit button the url link need to be send the respected email id ,in encrypted format.I already done as a normal link,but need to send an encrypted link.
Note: all i need in mvc4

What I have tried:

controller
C#
public ActionResult Index(MailModel model)
      {
          using (MailMessage mm = new MailMessage("name@gmail.com", model.To))
          {
              string url = "http://localhost:49458/SendMailer/Login";
              string body = "Hello " + model.name + ",";
              body += "<br /><br />Please click the following link for Login Page";
              body += "<br /><a href = '"+url+ "'>Click here to go Login Page</a>";
              body += "<br /><br />Thanks";
              mm.Body = body;
              mm.IsBodyHtml = true;
              SmtpClient smtp = new SmtpClient();
              smtp.Host = "smtp.gmail.com";
              smtp.EnableSsl = true;
              NetworkCredential NetworkCred = new NetworkCredential("name@gmail.com", "pwd");
              smtp.UseDefaultCredentials = true;
              smtp.Credentials = NetworkCred;
              smtp.Port = 587;
              smtp.Send(mm);
          }
          return View();
      }

view
C#
<fieldset>
    <legend>
        Send Email
    </legend>
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary()
      
        <p>To: </p>
        <p>@Html.TextBoxFor(m => m.To)</p>
        <p>name: </p>
        <p>@Html.TextBoxFor(m => m.name)</p>
        <p>From mail: </p>
        <p>@Html.TextBoxFor(m => m.Email)</p>

        <input type="submit" value="Send" />
    }  </fieldset>

model
C#
public class MailModel
{
    public string To { get; set; }
      public string Email { get; set; }
    public string name { get; set; }
}
Posted
Updated 15-Aug-22 21:20pm
v2
Comments
jimmson 25-May-17 3:46am    
Remove your email credentials from the question ASAP and change the password to your email, unless they are fake.
GrpSMK 25-May-17 3:57am    
tq,do you know the answer?
Manasa Mididhoddi 16-Aug-22 3:25am    
Can you please help me, how to send an encrypted url to a user that he can click and upon clicking he will open a page

HI!! If I am not mistaken are you looking for this? Please follow this link and let me know.

Encrypt and Decrypt URL in MVC 4 – DotNetTrace.Net[^]
 
Share this answer
 
Comments
GrpSMK 25-May-17 3:57am    
yea but i need to send that link in mail
F-ES Sitecore 25-May-17 4:24am    
The action attribute code can still be used, but rather than using EncodedActionLink to create the url, take the code in that that encrypts the params and use it directly in your code. Alternatively just google "c# encrypt decrypt string" and you'll find lots of examples of encrypting or decrypting strings...find one you like and use it to encrypt in your mailing code and decrypt in your action.
GrpSMK 25-May-17 6:06am    
encrypted and and send the string to email,now how to open the link from email?using decrypt
F-ES Sitecore 25-May-17 6:08am    
Just to clarify, you can't encrypt the whole link otherwise the browser doesn't know where to go, you can only encrypt the parameters.
F-ES Sitecore 25-May-17 6:24am    
You can't. If you want something to be secret don't put it on the internet. Think about it, how insecure would the internet be if you could encrypt urls so people don't know where they are about to be taken to? You need to find a different solution to the actual problem you are trying to solve.
I have found one post online. Can you please go through it ? Let me know

Rusty Divine | How to encrypt a password reset email link in asp.Net MVC[^]
 
Share this answer
 
Comments
GrpSMK 25-May-17 5:17am    
yea good one,but no need to reset passwords here just send the url in encrypted format,how to do it?
GrpSMK 25-May-17 6:05am    
encrypted and and send the string to email,now how to open the link?using decrypt
Manasa Mididhoddi 16-Aug-22 3:25am    
Can you please help me, how to send an encrypted url to a user that he can click and upon clicking he will open a page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900