我们正在发送带有查询字符串值的电子邮件。但邮件中的查询字符串值未显示在激活链接:
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
{
}
答案 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
{
}
}