コード例 #1
0
ファイル: SendMail.cs プロジェクト: anitha1993/dept-EmpMgmt
        public string GenerateRandomPassword()
        {
            Employee employee = new Employee();
            ApplicationDbContext context = new ApplicationDbContext();

            string PasswordLength = "12";
            string NewPassword = "";
            employee.RandomPassword = NewPassword;

            string allowedChars = "";
            allowedChars = "1,2,3,4,5,6,7,8,9,0";
            allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
            allowedChars += "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
            allowedChars += "~,!,@,#,$,%,^,&,*,+,?";

            char[] sep = { ',' };
            string[] arr = allowedChars.Split(sep);

            string IDString = "";
            string temp = "";

            Random rand = new Random();

            for (int i = 0; i < Convert.ToInt32(PasswordLength); i++)
            {
                temp = arr[rand.Next(0, arr.Length)];
                IDString += temp;
                NewPassword = IDString;
            }

            return NewPassword;
        }
コード例 #2
0
        ////private void SendEMail(string emailid, string subject, string body)
        ////{
        ////    SmtpClient client = new SmtpClient();
        ////    client.DeliveryMethod = SmtpDeliveryMethod.Network;
        ////    client.EnableSsl = true;
        ////    client.Host = "smtp.gmail.com";
        ////    client.Port = 587;
        ////    NetworkCredential credentials = new NetworkCredential("*****@*****.**", "amazinggrace");
        ////    client.UseDefaultCredentials = false;
        ////    client.Credentials = credentials;
        ////    MailMessage msg = new MailMessage();
        ////    msg.From = new MailAddress("*****@*****.**");
        ////    msg.To.Add(new MailAddress(emailid));
        ////    msg.Subject = subject;
        ////    msg.IsBodyHtml = true;
        ////    msg.Body = body;
        ////    client.Send(msg);
        ////}
        public void SendMail(string Email, string emailBody, string password)
        {
            Employee employee = new Employee();
            SmtpClient smtpClient = new SmtpClient();

            //   var mailMessage = new MailMessage(((NetworkCredential)(smtpClient.Credentials)).UserName, to, subject, body);

            var mailMessage = new MailMessage(((NetworkCredential)(smtpClient.Credentials)).UserName, Email, "User confirmation", "Thank you for your registration! Your Password is <b>" + password + "</b> Please login and change the password.");

            // MailMessage mailMessage = new MailMessage();

            //////var to = mailMessage.To.Add(Email);
            //////var subject = mailMessage.Subject = "User confirmation";
            //////var body = mailMessage.IsBodyHtml = true;
            //////mailMessage.Body = string.Format("Thank you for your registration! Your Password is <b>" + password + "</b> Please login and change the password.");

            //  smtpClient.UseDefaultCredentials = true;
            smtpClient.Send(mailMessage);
        }