我正在为我的网页创建一个注册页面,我希望人们收到一封激活邮件,但我不知道如何实现这一点。
这就是我调用数据库的代码的样子
DBconnect dbcon = new DBconnect();
if (dbcon.Checkmail(tbx_Remail.Text) == true)
{
lbl_Remail.Text = "This email is already used";
}
else
lbl_Remail.Text = "";
if (tbx_Rpassword.Text == tbx_Rrenter.Text && lbl_Remail.Text!="")
{
Mail mail = new Mail();
Hashing hash = new Hashing();
Account acc = new Account("user", tbx_Rname.Text, tbx_Rcity.Text, tbx_Rstate.Text, tbx_Remail.Text, tbx_Rpostal.Text, tbx_Radress.Text, tbx_Rtelephone.Text, hash.hashpass(tbx_Rpassword.Text, "asIoqc"));
dbcon.CreateAccount(acc);
mail.ActivationEmail(tbx_Remail.Text, "test", tbx_Remail.Text);
btn_Rreset_Click(this, new EventArgs());
}
我的数据库设置了一个激活列,该列的默认设置为 1,当激活 = 1 时,您无法登录。
这是邮件类的样子
public bool ActivationEmail(string username, string message, string email)
{
try
{
MailMessage Message = new MailMessage();
SmtpClient Smtp = new SmtpClient();
System.Net.NetworkCredential SmtpUser = new System.Net.NetworkCredential();
// Basis gegevens email
Message.From = new MailAddress("xxx@xxx.com", "no-reply@xxx.com");
Message.To.Add(new MailAddress(email, username));
Message.IsBodyHtml = true;
// Gegevens onderwerp & Body
Message.Subject = "Account Activation";
Message.Body = message;
// SMTP Auth, een emailadres welke is aangemaakt in het control panel
SmtpUser.UserName = "xxx";
SmtpUser.Password = "xxx";
// Bericht verzenden
Smtp.UseDefaultCredentials = false;
Smtp.Credentials = SmtpUser;
Smtp.Port = 80;
Smtp.Host = "xxx";
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
Smtp.Send(Message);
return true;
}
catch
{
return false;
}
}
我希望有人可以帮助我现在应该做什么,因为我以前从未这样做过。