Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i need coding how to send email through gmail.
first i know email id.i forget my password through email i will get password.first i need to check that mail id is in our database or not.if its there i will send that password through gmail server could help me for this
Posted
Updated 1-Mar-12 21:11pm
v2

Don't.
Never store the password. Instead, reset it to a random value, and email that to the user instead, with a link to the "Change password" page.

Storing passwords in any readable form is a bad idea - ask Sony!
 
Share this answer
 
Comments
sankarreddyece 2-Mar-12 3:22am    
how to get that random value could you give coding
for that
OriginalGriff 2-Mar-12 3:57am    
Personally, I use a Guid:
string newPassword = Guid.NewGuid().ToString();
That is long enough and random enough, and annoying enough that they will change it immediately to something they stand a chace of remembering!
However, if you are using Membership there is also:
http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx
Which is quite often used.
Try this
C#
public string GetRandomString(int length)
        {
            System.Random rnd = new Random();
            //string charPool = "abc890defghijkl1234mnopqrstuvwxyz567";
            string charPool = "ABC890DEFGHIJKL1234MNOPQRSTUVWXYZ567";
            System.Text.StringBuilder rs = new System.Text.StringBuilder();
            while (length-- > 0)
                rs.Append(charPool[(int)(rnd.NextDouble() * charPool.Length)]);
            return rs.ToString();
        }

or use Guid
to get a random string
 
Share this answer
 
try this

if(true)
{
           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 );
}
else
  Label.Text="the email id is does not exist";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900