如何通过邮件发送密码 [英] how send password through mail

查看:85
本文介绍了如何通过邮件发送密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["sampleConnectionString"].ToString();
        DataTable dt = new DataTable();
        con.fetch("select username,password from register where email='" + TextBox3.Text + "'", ref dt);
        DataTable dt = new DataTable();

        if (dt.Rows.Count == 0)
        {
            Response.Redirect("~/Default.aspx");
        }
        else
        {
            try
            {
                MailMessage mm = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                mm.From = new MailAddress(TextBox3.Text);
                //mm.CC.Add("");
                mm.To.Add(new MailAddress("sankarreddyece@gmail.com"));
                mm.Subject = "this is password recovary email";
                mm.Body = "your  username is :-" + dt.Rows[0][0].ToString() + " and your password is:-" + dt.Rows[0][1].ToString() + "";
                mm.IsBodyHtml = true;
                smtp.Host = "smtp.gmail.com"; //You can add this in the webconfig
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = "sankarreddyece@gmail.com ";
                NetworkCred.Password = "ksr@740640";
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587; //this is Gmail port for e-mail
                smtp.Send(mm);//send an e-mail
                Response.Write("password sented");
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }




您好,可以使用此代码发送忘记密码s.但是它没有显示任何错误.邮件也没有发送.任何机构可以纠正此问题吗?




hi can use this code for sending forget password s.but it doesn''t show any error.mail also not sented .can any body rectify this

推荐答案

http://www.shabdar. org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html [ http://csharp.net-informations.com/communications/csharp-smtp-mail.htm [^ ]
http://www.shabdar.org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html[^]

http://csharp.net-informations.com/communications/csharp-smtp-mail.htm[^]


通过电子邮件发送密码是一个坏主意,有人可以监视您的通讯并获取密码.

并非所有人都知道,有一种安全的方法可以通过绝对开放的通信渠道交换机密信息,并且即使对这两个参与者都被烧死之前一直监视该信道的人也可以将消息保密.如此多的人与我争辩说这是不可能的!他们争辩说,如果两个伙伴需要彼此说特别",那么中间的人也可以在这里说到.这些考虑是基于微妙的逻辑缺陷.

但是,这种方法以通用名称公钥密码学广为人知:
http://en.wikipedia.org/wiki/Public-key_cryptography [ http://msdn.microsoft.com/en-us/library/system. security.cryptography.asymmetricalgorithm.aspx [ ^ ].

—SA
Sending a password via e-mail is a bad idea someone can spy on your communication and get the password.

Not everyone knows that there is a secure way to exchange secret information through absolutely open channels of communication and keep the messages in secret even from the one who was spying on the channel since before both participants were burn. So many people argues with me that this is impossible! They argued that if as soon as the two partners need to say "something special" to each other, the man in the middle can here it, too. Such considerations are based on a subtle logical flaw.

Nevertheless, such methods are widely known under the common name public-key cryptography:
http://en.wikipedia.org/wiki/Public-key_cryptography[^].

Follow the action taken by Alice and Bob to make sure was right.

Such algorithms are well available in .NET. Please see:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.asymmetricalgorithm.aspx[^].

—SA


尝试一下,
try this,
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );

newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";

////For File Attachment, more file can also be attached

Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );

SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential             ( "mail@gmail.com", "pwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );


这篇关于如何通过邮件发送密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆