Example:
string activationCode = System.Guid.NewGuid().ToString();
string bodyText = "<a href="$href$?ActivationCode=$ActivationCode$">Click Here</a>";
string url = System.Web.HttpContext.Current.Request.Url.ToString();
int i = url.LastIndexOf('/');
url = url.Remove(i + 1);
url += "Activate.aspx";
bodyText = bodyText.Replace("$ActivationCode$", activationCode);
bodyText = bodyText.Replace("$href$", url);
SendEmail("Admin",
"a@a.com",
"hi",
bodyText);
public static void SendEmail(string sender, string receiver, string subject, string body)
{
string fromEmail = ConfigurationManager.AppSettings["ADMIN_EMAIL"].ToString();
string password = ConfigurationManager.AppSettings["ADMIN_EMAIL_PASSWORD"].ToString();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(fromEmail, password);
string bodyText = Regex.Replace(body, @"<(.|\n)*?>", string.Empty);
var plainView = AlternateView.CreateAlternateViewFromString(bodyText, null, "text/plain");
var htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
var mail = new MailMessage
{
From = new System.Net.Mail.MailAddress(sender, "Farolito's Journey"),
ReplyTo = new System.Net.Mail.MailAddress(sender, "Farolito's Journey"),
BodyEncoding = Encoding.GetEncoding("utf-8"),
Subject = subject
};
mail.To.Add(new MailAddress(receiver));
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);
mail.Priority = MailPriority.High;
var client = new SmtpClient
{
Host = ConfigurationManager.AppSettings["ADMIN_EMAIL_HOST"].ToString(),
UseDefaultCredentials = false,
Credentials = cred
};
try
{
client.Send(mail);
}
catch (Exception)
{
}
mail = null;
}
}
In Activate.aspx
if (Request.QueryString["ActivationCode"] == null)
Response.Redirect("Default.aspx");
string activitionCode = Request.QueryString["ActivationCode"];