如何在链接中使用查询字符串值发送电子邮件

时间:2013-02-21 05:20:40

标签: asp.net

我们正在发送带有查询字符串值的电子邮件。但邮件中的查询字符串值未显示在激活链接:

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

这里uniqueid是随机生成的值,随机生成的值不显示在链接中。

电子邮件中的链接(http://www.example.com/SignUp.aspx?nyckel= uniqueid),代替 (http://www.example.com/SignUp.aspx?nyckel= XXXXXXX)。

以下是代码:

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
        {                
        }

1 个答案:

答案 0 :(得分:1)

您需要将uniqueid字符串连接到为msg.Body创建的字符串。要在C#中连接字符串,请在两个字符串之间使用连接运算符+

    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
        {                
        }
    }