通过 C# 发送 OTP 电子邮件

问题描述

我正在尝试创建一个简单的注册系统,该系统通过我的 yahoo 电子邮件随机数作为 OTP 发送到用户的电子邮件,以验证电子邮件。但是它不能正常工作,代码只是将电子邮件和密码添加数据库

此后网页一直在加载

namespace WebApplication1
{
    public partial class VerificationPage : System.Web.UI.Page
    {
        sqlConnection con = new sqlConnection(ConfigurationManager.ConnectionStrings["login"].ConnectionString);
        protected void Page_Load(object sender,EventArgs e)
        {
            //Open Connection
            con.open();
        }


        protected void Button1_Click1(object sender,EventArgs e)
        {
            //Insert Email & Password into database
           
            sqlCommand cm = new sqlCommand("insert into Reg(Email,Password) values('" + Email.Text + "','" + Password.Text + "')",con);
            cm.ExecuteNonQuery();
      
             //Store email in 'umail' variable    
            String umail = Email.Text;

            //generate random number
            Random rnd = new Random();
            int vkey = rnd.Next(111111,999999);

            //insert number into vkey
            sqlCommand cmd = new sqlCommand("insert into Reg (Vkey) values('"+ vkey +"')",con);

            //close connection
         

            //send mail with verification number
            Console.WriteLine(umail);
            MailAddress to = new MailAddress(Console.ReadLine());

            Console.WriteLine("wbassignment@yahoo.com");
            MailAddress from = new MailAddress(Console.ReadLine());

            MailMessage mail = new MailMessage(from,to);

            Console.WriteLine("Verification key");
            mail.Subject = Console.ReadLine();

            Console.WriteLine(vkey);
            mail.Body = Console.ReadLine();

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.yahoo.com";
            smtp.Port = 587;

            smtp.Credentials = new NetworkCredential(
                "here goes email","here goes password");
            smtp.EnableSsl = true;
            Console.WriteLine("Sending email...");
            smtp.Send(mail);

            //redirect to confirmation page
            Response.Redirect("http://localhost:9275/confirmation.aspx");

            con.Close();

        }


    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)