I have been foloowing this guide http://www.aspsnippets.com/Articles/Send-user-Confirmation-email-after-Registration-with-Activation-Link-in-ASPNet.aspx to create a system that send validation email on register and I seem to have stumbled into a small issue since the guide is suitable for Web Application and I need to modify it for Console Application,
this piece of code is suitable for web application but i'm trying to change it to suit a console application.
body += "<br /><a href = '" +Request.Url.AbsoluteUri.Replace("CS.aspx", "CS_Activation.aspx?ActivationCode=" + activationCode) + "'>Click here to activate your account.</a>";
Tried reading about WebClient or the Uri options but I dont seem to figure out how to fetch the absolute Uri and add the required string to generate the activation link from a Console application.
Will add more code if required.
Tried following this SO How to build a Url? but I cant seem to make it work properly.
Activation Code Generation and saving it on DB.
private static void SendActivationEmail(string email, string userName, MySqlConnection mysqlCon)
{
string activationCode = Guid.NewGuid().ToString();
using (mysqlCon)
{
using (MySqlCommand cmd = new MySqlCommand("UPDATE accounts SET ActivationCode=@ActivationCode " +
"WHERE Username=@Username;"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Username", userName);
cmd.Parameters.AddWithValue("@ActivationCode", activationCode);
cmd.ExecuteNonQuery();
mysqlCon.Close();
}
}
}