在asp.net中发送电子邮件...帮助我..... [英] email in asp.net...help me.....

查看:79
本文介绍了在asp.net中发送电子邮件...帮助我.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个社交网站.我面临的问题是当用户忘记密码时发送电子邮件.谁能帮我解决这个问题????

解决方案

您必须添加以下代码以尽可能简单地发送邮件. ..

[示例给出了gmail帐户.
这意味着您必须拥有一个gmail帐户才能将邮件发送到任何地址.]

string pweda = "FromMailPassword"; //(ConfigurationManager.AppSettings["password"]);
        string from = "FromYourmail@gmail.com"; //Replace this with your own correct Gmail Address
        string to = "abc@gef.com"; //Replace this with the Email Address to whom you want to send the mail
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = "This is a test mail";
        mail.SubjectEncoding = System.Text.Encoding.UTF8;
        mail.Body = "Test Mail.";

        mail.Priority = MailPriority.High;
        SmtpClient client = new SmtpClient();

        //Add the Creddentials- use your own email id and password
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(from, pweda);
        client.Port = 587; // Gmail works on this port
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true; //Gmail works on Server Secured Layer

        try
        {
            client.Send(mail);
            Response.Write("Message Sent...");
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
            string errorMessage = string.Empty;
            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
                ex2 = ex2.InnerException;
            }
            HttpContext.Current.Response.Write(errorMessage);
        } // end try



如果您有其他任何邮件,也可以从任何邮件地址发送.
只需替换为可从google轻松获得的凭据以及端口和主机名即可.

您可以通过将值分配给"mail.Body"来发送任何内容.

将此代码添加到您想发送邮件的任何地方...

编码愉快……..


将密码直接发送到邮件ID不是更好的主意
使用密码恢复
密码恢复讨论

或者如果您想直接发送,请尝试
使用asp.net发送邮件


使用密码恢复控件

此处 [ ^ ]

谢谢
--RA


i am building a social networking site. The problem which i m facing is to send an email when user forgot password. Could any one help me to come out from this problem??????

解决方案

You have to add the following codes to send a mail as simple as possible...

[Example is given for gmail account.
That means you have to have one gmail account to send a mail to any address.]

string pweda = "FromMailPassword"; //(ConfigurationManager.AppSettings["password"]);
        string from = "FromYourmail@gmail.com"; //Replace this with your own correct Gmail Address
        string to = "abc@gef.com"; //Replace this with the Email Address to whom you want to send the mail
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = "This is a test mail";
        mail.SubjectEncoding = System.Text.Encoding.UTF8;
        mail.Body = "Test Mail.";

        mail.Priority = MailPriority.High;
        SmtpClient client = new SmtpClient();

        //Add the Creddentials- use your own email id and password
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(from, pweda);
        client.Port = 587; // Gmail works on this port
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true; //Gmail works on Server Secured Layer

        try
        {
            client.Send(mail);
            Response.Write("Message Sent...");
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
            string errorMessage = string.Empty;
            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
                ex2 = ex2.InnerException;
            }
            HttpContext.Current.Response.Write(errorMessage);
        } // end try



You can send from any mail address if you have any other...
Just replace with the credentials and port and host names which you can get easily get from google.

You can send anything by assigning value to ''mail.Body''.

Add this code where ever you want send the mail...

Happy coding........


It not be a better idea to send password direct to mail id
use Password Recovery
Password Recovery discussion

or if you want to send directly then try
Sending mail in asp.net


us the Password recovery control,

Here[^]

Thanks
--RA


这篇关于在asp.net中发送电子邮件...帮助我.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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