Esempio n. 1
0
        public ResultMessagesReponse SendMail_ForgetPassword(UserInfo userInfo)
        {
            SendEmailCore         m_sendEmailCore         = new SendEmailCore();
            ResultMessagesReponse MyResultMessagesReponse = new ResultMessagesReponse();

            try
            {
                const string sql        = @"Select * from users Where userEmail=@email;";
                UserInfo     MyUserInfo = this._db.Query <UserInfo>(sql, new Dictionary <string, object> {
                    { "email", userInfo.userEmail }
                }).FirstOrDefault();
                string FromUserEmail    = ConfigurationManager.AppSettings["FromUserEmail"];
                string FromUserPassword = ConfigurationManager.AppSettings["FromPassword"];

                if (MyUserInfo != null)
                {
                    string EncryEmail  = Convert.ToBase64String(Encoding.UTF8.GetBytes(MyUserInfo.userEmail));
                    string _EncryEmail = EncryEmail.Replace("=", "*");

                    MyUserInfo.FromUserEmail = FromUserEmail;
                    MyUserInfo.FromPassword  = FromUserPassword;
                    MyUserInfo.UI_PageURL    = userInfo.UI_PageURL;
                    string EncryptEmail = _EncryEmail;
                    bool   CheckStatus  = m_sendEmailCore.SendEmail_forgetPassword(MyUserInfo, EncryptEmail);
                    if (CheckStatus == true)
                    {
                        //MyResultMessagesReponse.Status = "0";
                        MyResultMessagesReponse.Status = "SUCCESS";
                    }
                }
                else
                {
                    MyResultMessagesReponse.Status = "FAIL";
                }
            }
            catch (Exception ex)
            {
                //TODO
                var MessageError = ex.ToString();
                MyResultMessagesReponse.Status = "FAIL";
                throw;
            }


            return(MyResultMessagesReponse);
        }
Esempio n. 2
0
        public ResultReponse SMTPValidate(string server, int port, string login, string password, string security, string authentication, string Subject, string Message)
        {
            ResultReponse MyResultReponse   = new ResultReponse();
            ResultReponse TempResultReponse = new ResultReponse();

            SendEmailCore MySendEmailCore = new SendEmailCore();

            string ReturnStr    = "";
            int    ResponseCode = 0;
            string MessageOk    = "";

            try
            {
                TcpClient     tClient = new TcpClient("gmail-smtp-in.l.google.com", 25);
                string        CRLF    = "\r\n";
                byte[]        dataBuffer;
                string        ResponseString;
                NetworkStream netStream = tClient.GetStream();
                StreamReader  reader    = new StreamReader(netStream);
                ResponseString = reader.ReadLine();
                /* Perform HELO to SMTP Server and get Response */
                dataBuffer = BytesFromString("HELO KirtanHere" + CRLF);
                netStream.Write(dataBuffer, 0, dataBuffer.Length);
                ResponseString = reader.ReadLine();
                dataBuffer     = BytesFromString("MAIL FROM:<*****@*****.**>" + CRLF);
                netStream.Write(dataBuffer, 0, dataBuffer.Length);
                ResponseString = reader.ReadLine();
                /* Read Response of the RCPT TO Message to know from google if it exist or not */
                dataBuffer = BytesFromString("RCPT TO:<" + login + ">" + CRLF);
                netStream.Write(dataBuffer, 0, dataBuffer.Length);
                ResponseString = reader.ReadLine();
                ResponseCode   = GetResponseCode(ResponseString);
                if (ResponseCode == 550)
                {
                    ReturnStr = "Mai Address Does not Exist !\n\n";
                    //ReturnStr += string.Format("<B><font color='red'>Original Error from Smtp Server :{0}</font></b>", ResponseString);

                    MyResultReponse.Status     = "NOTEXISTS";
                    MyResultReponse.StatusCode = "NOTEXISTS";

                    MyResultReponse.Data    = ReturnStr;
                    MyResultReponse.Message = ReturnStr;
                }
                else if (ResponseCode == 250)
                {
                    MessageOk = "OK";
                }
                /* QUITE CONNECTION */
                dataBuffer = BytesFromString("QUITE" + CRLF);
                netStream.Write(dataBuffer, 0, dataBuffer.Length);
                tClient.Close();
                MyResultReponse.Status = "SUCCESS";
                if (MyResultReponse.Status == "SUCCESS")
                {
                    TempResultReponse = MySendEmailCore.SendTestEmail(server, port, login, login, password, Subject, Message);
                    if (TempResultReponse.Status == "SUCCESS")
                    {
                        MyResultReponse.Status     = "SUCCESS";
                        MyResultReponse.StatusCode = "SUCCESS";

                        MyResultReponse.Message = "Message Sent";
                    }
                    else
                    {
                        MyResultReponse.Status     = "ERROR";
                        MyResultReponse.StatusCode = "ERROR";
                        MyResultReponse.Data       = TempResultReponse.Data;
                        //MyResultReponse.Message = "Email Validated password musth be wrong";

                        MyResultReponse.Message = "Email Account Password Not Validated";
                    }
                }
                //*************************************************************************************************************************************
                //Send Email
                //*************************************************************************************************************************************
                // If using Professional version, put your serial key below.
                //ComponentInfo.SetLicense("FREE-LIMITED-KEY");

                //using (GemBox.Email.Smtp.SmtpClient smtp = new GemBox.Email.Smtp.SmtpClient(server))
                //{
                //    // Connect to mail server
                //    smtp.Connect();
                //    Console.WriteLine("Connected.");

                //    // Authenticate with specified username and password
                //    // (SmtpClient will use strongest possible authentication mechanism)
                //    smtp.Authenticate(login, password);
                //    Console.WriteLine("Authenticated.");

                //    // Create new message
                //    GemBox.Email.MailMessage message = new GemBox.Email.MailMessage(login,login);
                //    message.Subject = Subject;
                //    //message.BodyText = Message;
                //    message.BodyHtml = Message;

                //    Console.WriteLine("Sending message...");

                //    // Send message
                //    smtp.SendMessage(message);

                //    MyResultReponse.Status = "SUCCESS";
                //    MyResultReponse.StatusCode = "SUCCESS";

                //    MyResultReponse.Message = "Message Sent";


                //}
                //*************************************************************************************************************************************

                //using (var client = new SmtpClient())
                //{
                //    client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);

                //    client.Authenticate("username", "password");

                //    foreach (var message in messages)
                //    {
                //        client.Send(message);
                //    }

                //    client.Disconnect(true);
                //}

                ReturnStr = "SUCCESS";
                return(MyResultReponse);
            }
            catch (Exception exp)
            {
                ReturnStr = "ERROR";
                MyResultReponse.Status     = "ERROR";
                MyResultReponse.StatusCode = "NOTEXISTS";

                MyResultReponse.Data    = ReturnStr;
                MyResultReponse.Message = exp.ToString();
            }
            return(MyResultReponse);
        }