public MainResponse SendEmailWithDocument(EmailWithDocumentRequest emailWithDocumentRequest)
        {
            var currentDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");

            currentDirectory = currentDirectory.Replace("\\", "/");
            string fullPath = currentDirectory + emailWithDocumentRequest.DocumentPath;
            string guid     = Guid.NewGuid().ToString();

            //get email settings
            var settings = _applicationRepository.GetAll().FirstOrDefault();

            // Send Email with document
            EmailRequest email = new EmailRequest();

            email.To              = emailWithDocumentRequest.EmailId;
            email.SenderEmail     = settings.CompanyEmail;
            email.CompanyEmail    = settings.CompanyEmail;
            email.CompanyPassword = settings.CompanyPassword;
            email.Url             = settings.ResetPasswordUrl;
            email.Token           = guid;
            email.TemplateType    = "Email With Document";

            _emailSenderRepository.SendEmailWithDocument(email, fullPath);

            _mainResponse.Message = Constants.EMAIL_SENT;
            _mainResponse.Success = true;

            return(_mainResponse);
        }
        public MainResponse SaveAndEmail(string fileBase64, string emailid)
        {
            try
            {
                _mainResponse.Message = "";
                var base64 = fileBase64.Split(",").Last();

                var base64firstdata     = fileBase64.Split(",").First();
                var base64firstfiletype = base64firstdata.Split(";").First();
                var index  = base64firstfiletype.IndexOf("/") + 1;
                var length = base64firstfiletype.Length;
                var type   = base64firstfiletype.Substring(index, length - index);



                var    filePath = SaveFileFromBase64(base64, type);
                string guid     = Guid.NewGuid().ToString();

                //get email settings
                var settings = _applicationRepository.GetAll().FirstOrDefault();

                // Send Email with document
                EmailRequest email = new EmailRequest();
                email.To              = emailid;
                email.SenderEmail     = settings.CompanyEmail;
                email.CompanyEmail    = settings.CompanyEmail;
                email.CompanyPassword = settings.CompanyPassword;
                email.Url             = settings.ResetPasswordUrl;
                email.Token           = guid;
                email.TemplateType    = "Email With Document";

                _emailSenderRepository.SendEmailWithDocument(email, filePath);
                if (File.Exists(filePath))
                {
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                    File.Delete(filePath);
                }
                _mainResponse.Message = "Email Sent";
            }
            catch
            {
                _mainResponse.Message = "Some Error Occurred";
            }
            return(_mainResponse);
        }
Esempio n. 3
0
        public MainResponse ForgotPassword(ForgotPasswordRequest forgotPasswordRequest)
        {
            var user = _userRepository.GetSingle(x => x.Email == forgotPasswordRequest.Email.ToLower() && x.IsDeleted == false);

            if (user != null)
            {
                string guid = Guid.NewGuid().ToString();
                user.ResetToken        = guid;
                user.ResetTokenExpired = DateTime.UtcNow.AddMinutes(60);
                _userRepository.Update(user);

                //get email settings
                var settings = _applicationRepository.GetAll().FirstOrDefault();

                // Send Fortget Password Email
                EmailRequest email = new EmailRequest();
                email.To              = forgotPasswordRequest.Email;
                email.SenderEmail     = settings.CompanyEmail;
                email.CompanyEmail    = settings.CompanyEmail;
                email.CompanyPassword = settings.CompanyPassword;
                email.Url             = settings.ResetPasswordUrl;
                email.Token           = guid;
                email.TemplateType    = "Forgot Password";

                _emailRepository.SendEmail(email);

                _mainResponse.Success = true;
                _mainResponse.Message = Constants.FORGET_PASSWORD_EMAIL;
            }
            else
            {
                _mainResponse.Success = false;
                _mainResponse.Message = Constants.NO_RECORD_FOUND;
            }
            return(_mainResponse);
        }