コード例 #1
0
        public void ResetPassWord(string _userName)
        {
            PasswordHasher     hasher            = new PasswordHasher();
            IPasswordGenerator gen               = new PasswordGenerator();
            ILoginUser         loggedInUser      = userRepo.GetUserByName(_userName) as ILoginUser;
            string             generatedPassword = gen.GeneratePassword(true, true, true, true, false, 12);

            userRepo.UpdatePassword(loggedInUser.UserID, hasher.HashWithSalt(generatedPassword), hasher.Key);
            EMailSender eMailer = new EMailSender(GlobalSettings.MailSettings.Client);

            try
            {
                IMessageSettableMail mail = new MessageMail(new System.Net.Mail.MailMessage());
                mail.MakeMail(GlobalSettings.MailSettings.ResetSubject, String.Format(GlobalSettings.MailSettings.ResetContent, generatedPassword), loggedInUser.Email);
                eMailer.Send(mail, GlobalSettings.MailSettings.NoReplyAdress, GlobalSettings.MailSettings.NetworkCredentials, GlobalSettings.MailSettings.EnableSSL, GlobalSettings.MailSettings.Port);
            }
            catch { }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var mailsender = new EMailSender(txtfrom.Text, txtto.Text);

            mailsender.Subject      = txtsubject.Text;
            mailsender.BCCAddresses = new List <string>()
            {
                txtbcc.Text
            };
            mailsender.CCAddresses = new List <string>()
            {
                "*****@*****.**"
            };
            mailsender.BodyContent = txtmsg.Text;
            if (mailsender.Send())
            {
                MessageBox.Show("Mesage sent successfully! :)");
            }
        }
コード例 #3
0
        public void SendEMail(string subject, string body, string recipient, string logarchivename)
        {
            string logarchivepath = String.IsNullOrEmpty(logarchivename) ?
                                    String.Empty : Path.Combine(Environment.GetEnvironmentVariable("TEMP"), logarchivename);

            try
            {
                createLogArchive(logarchivepath);
            }
            catch (Exception ex) // Any exception from ZipFile.CreateFromDirectory()
            {
                throw new LogCollectException(ex);
            }

            try
            {
                EMailSender.Send(logarchivepath, _email, recipient, body, subject);
            }
            catch (Exception ex) // Any exception from external API
            {
                throw new SendEMailException(ex);
            }
        }
コード例 #4
0
        private void btnBug_Click(object sender, EventArgs e)
        {
            bool mailSent = false;

            try
            {
                if (!(string.IsNullOrEmpty(ConfigReader.FromAddress) || string.IsNullOrEmpty(ConfigReader.ToAddress)))
                {
                    EMailSender mailSender = new EMailSender();
                    mailSender.FromAddress = ConfigReader.FromAddress;
                    List <string> toAddresses = new List <string>()
                    {
                        ConfigReader.ToAddress
                    };
                    mailSender.ToAddresses = toAddresses;
                    mailSender.IsBodyHTML  = false;
                    mailSender.Subject     = this.GetMailErrorSubject();
                    mailSender.BodyContent = this.GetMailErrorBody();
                    mailSent = mailSender.Send();
                }
                if (mailSent)
                {
                    lblInformation.Text = MAIL_SENT_CONFIRMATION_MSG.ToCurrentCulture();
                }
                else
                {
                    lblInformation.Text = MAIL_NOT_SENT_CONFIRMATION_MSG.ToCurrentCulture();
                }
            }
            catch (Exception ex)
            {
                lblInformation.Text = string.Format("{0}-{1}", MAIL_NOT_SENT_CONFIRMATION_MSG.ToCurrentCulture(), ex.Message);
                new ErrorLogger(new ExceptionData(ex)).LogException();
                emailSendingError     = ex;
                lblInformation.IsLink = true;
            }
        }
コード例 #5
0
        public bool CreateUser(RegisterViewModel vm)
        {
            IObjectPair <IRegisterUser, string> generatedUserPassPair = registerHandler.CreateUser(userRepo.GetAll(), vm.Firstname, vm.Lastname, vm.Email, vm.IsAdmin, vm.Phonenumber, vm.Country, vm.City, vm.Streetname, vm.Zip);

            try
            {
                userRepo.AddUser(generatedUserPassPair.Object1);
                ILoginUser user = userRepo.GetUserByName(generatedUserPassPair.Object1.UserName);
                if (vm.ProfilePicture != null)
                {
                    pictureHandler.PictureCopy(vm.ProfilePicture, user.UserID);
                }
                EMailSender          eMailer = new EMailSender(GlobalSettings.MailSettings.Client);
                IMessageSettableMail mail    = new MessageMail(new System.Net.Mail.MailMessage());
                mail.MakeMail(GlobalSettings.MailSettings.NewUserSubject, String.Format(GlobalSettings.MailSettings.NewUserContent, user.UserName, generatedUserPassPair.Object2), user.Email);
                eMailer.Send(mail, GlobalSettings.MailSettings.NoReplyAdress, GlobalSettings.MailSettings.NetworkCredentials, GlobalSettings.MailSettings.EnableSSL, GlobalSettings.MailSettings.Port);
            }
            catch
            {
                return(false);
                //throw new ArgumentException("Something went wrong with the registration. Check Inner Exception for specific information: /n" + excepton.InnerException.Message);
            }
            return(true);
        }