priw
priw

Reputation: 51

How to Send Email with query string value in a link

We are sending Email with query string value. But querystring value in a mail not showing in activation Link:

msg.Body = "<a href=\'http://www.example.com/SignUp.aspx?nyckel= uniqueid'>Click</a>";

Here uniqueid is random generated value, and random generated value not showing in a Link.

Link in Email (http://www.example.com/SignUp.aspx?nyckel= uniqueid), showing in place of (http://www.example.com/SignUp.aspx?nyckel= XXXXXXX).

Here is the code:

public static void sendMail(string Email, string uniqueid)
    {   
        uniqueid = GenerateRandom.GetUniqueReferalid(14);
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("Admin");
        string _toId = Email.ToString();
        msg.To.Add(new MailAddress(_toId));
        msg.Subject = ("Refer a Friend");   
        msg.IsBodyHtml = true;
        msg.Body = "<a href=\'http://www.example.com/SignUp.aspx?nyckel=uniqueid'></a>";
        SmtpClient client = new SmtpClient();
        client.EnableSsl = true;
        client.UseDefaultCredentials = true;
        try
        {
            client.Send(msg);              
        }
        catch
        {                
        }

Upvotes: 1

Views: 4119

Answers (1)

Christopher.Cubells
Christopher.Cubells

Reputation: 911

You need to concatenate your uniqueid string to the string you are creating for msg.Body. To concatenate strings in C# use the concatenate operator + between two strings.

    public static void sendMail(string Email, string uniqueid)
    {   
        uniqueid = GenerateRandom.GetUniqueReferalid(14);
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("Admin");
        string _toId = Email.ToString();
        msg.To.Add(new MailAddress(_toId));
        msg.Subject = ("Refer a Friend");   
        msg.IsBodyHtml = true;
        msg.Body = "<a href='http://www.xxx.com/SignUp.aspx?nyckel=" + uniqueid + "'></a>";
        SmtpClient client = new SmtpClient();
        client.EnableSsl = true;
        client.UseDefaultCredentials = true;
        try
        {
            client.Send(msg);              
        }
        catch
        {                
        }
    }

Upvotes: 1

Related Questions