Exemplo n.º 1
0
        public bool SendEmail()
        {
            bool bRet      = false;
            var  fromName  = Resources.WebsiteVariables.EmailFromName;
            var  fromEmail = Resources.WebsiteVariables.EmailFromEmail;

            string strIp  = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
            string strRef = System.Web.HttpContext.Current.Request.UrlReferrer.Host;

            List <EmailParameter> ep = new List <EmailParameter> {
                new EmailParameter("NAME", Name),
                new EmailParameter("EMAIL", Email),
                new EmailParameter("PHONE", Phone),
                new EmailParameter("COMPANY", Company),
                new EmailParameter("SUBJECT", Subject),
                new EmailParameter("MESSAGE", Message),
                new EmailParameter("IP", strIp),
                new EmailParameter("REFERRER", strRef)
            };

            int r1 = new EmailServer().EmailSend("EmailContact", new MailType(fromEmail), ep, null);

            bRet = r1 >= 0 ? true : false;

            return(bRet);
        }
Exemplo n.º 2
0
        public async Task CanSendEmail()
        {
            EmailServer emailServer = new EmailServer("Mail Admin", "*****@*****.**", "password", "mail.bluehorizonng.com");
            //EmailServer emailServer = new EmailServer("Mail Admin", "*****@*****.**", "password", "mail.bluehorizonng.com", port: 587);

            Email email = new Email();

            //email.ToEmailAddress = new EmailAddress() { Name = "Isioma", Email = "*****@*****.**" };
            email.ToEmailAddress = new EmailAddress()
            {
                Name = "Isioma", Email = "*****@*****.**"
            };
            email.FromEmailAddress = new EmailAddress()
            {
                Name = emailServer.Name, Email = emailServer.Username
            };

            //email.FromEmailAddress = new EmailAddress() { Name = "Isioma", Email = "*****@*****.**" };
            //email.ToEmailAddress = new EmailAddress() { Name = emailServer.Name, Email = emailServer.Username };
            email.Message = "Please throw more light on your e-commerce service";
            email.Subject = "Information Request";

            try
            {
                IEmailService emailService = new EmailService(emailServer);
                await emailService.SendEmailAsync(email);
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
        }
Exemplo n.º 3
0
        public void SendEmailWithHouseRanking(string ranking)
        {
            string      emailSubject = string.Format(EMAIL_SUBJECT, ranking);
            EmailServer emailServer  = new EmailServer(this._emailAddresses, null, emailSubject);

            emailServer.SendEmail();
        }
Exemplo n.º 4
0
        public HomeController(IEmailService emailService, EmailServer emailServer)
        {
            Guard.NotNull(emailService, nameof(emailService));
            Guard.NotNull(emailServer, nameof(emailServer));

            _emailServer  = emailServer;
            _emailService = emailService;
        }
            public void Send()
            {
                var emailServer = new EmailServer();

                foreach (var message in _pendings)
                {
                    emailServer.Send(message);
                }
            }
Exemplo n.º 6
0
            public void Send()
            {
                var emailServer = new EmailServer();

                _pendings.AsParallel().ForAll(m =>
                {
                    emailServer.Send(m);
                    SendCompleted?.Invoke(this, m);
                });
            }
Exemplo n.º 7
0
        /// <summary>进行用户重置密码操作的处理
        /// </summary>
        /// <returns>返回重置密码操作的结果</returns>
        public ActionResult ResetPwd()
        {
            string email = Request["email"];
            string pwd   = EncryptUtil.GenerateRandomPassword();

            string content = string.Format("您的新密码是:{0}, 请登录网站{1}修改你的密码", pwd, "http://xxx/");

            EmailServer.SendEmail(email, "", content);
            return(Content("邮件已经发送,请查收"));
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     _es = new EmailServer(
         address: "smtp.gmail.com",
         port: 587,
         isSSL: true,
         fromAddress: "*****@*****.**",
         password: "******"
         );
 }
        public void When_UsingEmailDelegate_Should_SendToEmail()
        {
            Document doc = new Document();

            doc.Text = "This is the Document's text";

            var emailServer   = new EmailServer();
            var emailDelegate = new Document.SendDocument(emailServer.SendEmail);

            Assert.AreEqual("Sending email", doc.SendAndReport(emailDelegate));
        }
Exemplo n.º 10
0
        private static void StartSmtpServer()
        {
            EmailServer emailServer;

            do
            {
                Console.WriteLine("Smtp Server running !!!");
                emailServer = new EmailServer(IPAddress.Loopback, 25);
                emailServer.Start();
            } while (emailServer != null);
        }
Exemplo n.º 11
0
        public AccountController(UserManager <User> userManager, SignInManager <User> signinManager, IEmailService emailService, EmailServer emailServer)
        {
            _userManager   = userManager;
            _signinManager = signinManager;
            _emailService  = emailService;
            _emailServer   = emailServer;

            //IAssemblyProvider
            //DefaultAssemblyProvider
            //IAssemblyLoaderContainer
            //IAssemblyLoadContextAccessor
        }
Exemplo n.º 12
0
        public static bool SendUpdateEmailVerificateEmail(string email, string verify_code)
        {
            EmailServer server = new EmailServer();

            string body = System.IO.File.ReadAllText(@"template\verify_email_source.html");

            body = body.Replace("{$$-USER_VERIFY_CODE-$$}", verify_code);
            body = body.Replace("{$$-USER_EMAIL_REASON-$$}", "更改绑定邮箱时产生");
            body = body.Replace("{$$-USER_EMAIL_REMINDER-$$}", "在进行用户邮箱绑定修改的关键过程中");

            return(server.Send(email, "KXT令牌", body));
        }
Exemplo n.º 13
0
    public async Task CreateAsync(EmailServer server, CancellationToken cancellationToken)
    {
        var entity = await _context.EmailServers.FirstOrDefaultAsync(s => s.Id == server.Id, cancellationToken);

        if (entity == null)
        {
            // TODO: Handle errors
            await _context.EmailServers.AddAsync(Encrypt(server), cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);
        }
    }
Exemplo n.º 14
0
        public void SaveEmailServerConfiguration(EmailServer data)
        {
            var info = _deployBusLogic.GetEmailServerConfiguration() ?? new EmailServerInfo();

            info.IsSsl        = data.IsSsl;
            info.Password     = data.Password;
            info.Port         = data.Port;
            info.Username     = data.Username;
            info.SmtpServer   = data.SmtpServer;
            info.ReplyAddress = data.ReplyAddress;

            _deployBusLogic.SaveEmailServerConfiguration(info);
        }
Exemplo n.º 15
0
        public int sendEmail(String Subject, String emailBody, List <string> TO, List <string> CC)
        {
            using (MailMessage mail = new MailMessage())
            {
                try
                {
                    mail.From = new MailAddress(EmailSetting.MailFrom);

                    if (TO != null)
                    {
                        foreach (string to in TO)
                        {
                            MailAddress copy = new MailAddress(to);
                            mail.To.Add(copy);
                        }
                    }

                    if (CC != null)
                    {
                        foreach (string cc in CC)
                        {
                            MailAddress copy = new MailAddress(cc);
                            mail.CC.Add(copy);
                        }
                    }

                    mail.Subject = Subject;
                    mail.Body    = emailBody;


                    mail.IsBodyHtml = false;
                    SmtpClient  smtp = new SmtpClient();
                    EmailServer es   = db.EmailServers.FirstOrDefault();
                    smtp.Host      = es.Host;
                    smtp.EnableSsl = es.EnableSsl;;
                    NetworkCredential networkCredential = new NetworkCredential(EmailSetting.MailFrom, EmailSetting.Password);
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials           = networkCredential;
                    smtp.Port = es.Port;
                    smtp.Send(mail);

                    ViewBag.Message = "Email Sent ";
                }
                catch (Exception e)
                {
                    ViewBag.Message = "Fail to send Email \r\n " + e.Message;;
                    return(0);
                }
                return(1);
            }
        }
Exemplo n.º 16
0
    public async Task UpdateAsync(EmailServer update, CancellationToken cancellationToken)
    {
        var entity = await _context.EmailServers.FirstOrDefaultAsync(s => s.Id == update.Id, cancellationToken);

        if (entity != null)
        {
            entity.Host            = update.Host;
            entity.Port            = update.Port;
            entity.FromAddress     = update.FromAddress;
            entity.UserName        = update.UserName;
            entity.FromDisplayName = entity.FromDisplayName;
            await _context.SaveChangesAsync(cancellationToken);
        }
    }
Exemplo n.º 17
0
        public bool TestEmailServerConnection(EmailServer data, string email = null)
        {
            var info = new EmailServerInfo
            {
                IsSsl        = data.IsSsl,
                Username     = data.Username,
                Password     = data.Password,
                SmtpServer   = data.SmtpServer,
                Port         = data.Port,
                ReplyAddress = data.ReplyAddress
            };

            return(_deployBusLogic.TestEmailServerConnection(info, email));
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            IClient      cl1    = new Client("Client1");
            IClient      cl2    = new Client("Client2");
            IClient      cl3    = new Client("Client3");
            IEmailServer server = new EmailServer();

            server.AddClient(cl1);
            server.AddClient(cl2);
            server.AddClient(cl3);

            server.NotifyClients();
            Console.ReadLine();
        }
Exemplo n.º 19
0
        public EmailServer GetEmailServerConfiguration()
        {
            var info        = _deployBusLogic.GetEmailServerConfiguration();
            var emailserver = new EmailServer()
            {
                IsSsl        = info.IsSsl,
                Port         = info.Port,
                SmtpServer   = info.SmtpServer,
                Username     = info.Username,
                Password     = info.Password,
                ReplyAddress = info.ReplyAddress
            };

            return(emailserver);
        }
Exemplo n.º 20
0
        public async Task <IActionResult> OnPostInvite()
        {
            Couple = await GetAuthorizedCouple();

            if (Couple == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid(nameof(Invite)))
            {
                return(Page());
            }

            Invite.EmailAddress = Invite.EmailAddress.ToLower();

            // Load the dinner itself, including other couples
            await Database.GetDinnerAsync(Couple.Dinner.ID);

            foreach (Couple storedCouple in Couple.Dinner.Couples)
            {
                if (storedCouple.EmailAddress == Invite.EmailAddress)
                {
                    ModelState.AddModelError(nameof(Invite), $"{ Invite.Person } met emailadres { Invite.EmailAddress } is al uitgenodigd.");
                    return(Page());
                }
            }

            // Invite
            Couple invitedCouple = await Database.CreateCoupleAsync(Couple.Dinner.ID, Invite.EmailAddress, Invite.Person);

            if (invitedCouple == null)
            {
                ModelState.AddModelError(nameof(Invite), $"Kan { Invite.Person } nu niet uitnodigen.");
                return(Page());
            }

            EmailServer.SendEmail(invitedCouple.EmailAddress, "Uitnodiging",
                                  $"U ben uitgenodigd door { Couple.PersonMain } om deel te namen aan een WalkingDinner. Bekijk uit uitnodiging <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Couples.SeeInvitationModel>( Request.Host, invitedCouple.ID, invitedCouple.AdminCode ) }\">Hier</a>");

            ViewData["InviteResult"] = $"{ Invite.Person } is uitgenodigd.";

            // Clear input data
            ModelState.Clear(nameof(Invite));
            Invite = null;

            return(Page());
        }
Exemplo n.º 21
0
        private EmailServer SaveEmailServer(EmailServer data)
        {
            try
            {
                _deployLogic.SaveEmailServerConfiguration(data);
                data.Status = CommandStatus.SavePassed;
            }
            catch (SmtpException exception)
            {
                ExceptionHandler.Manage(exception, this, Layer.UILogic);

                data.Status = CommandStatus.SaveFailed;
                _log.ErrorFormat("Save Failed.");
            }

            return(data);
        }
Exemplo n.º 22
0
    private EmailServer Encrypt(EmailServer server)
    {
        // TODO: Get key from elsewhere
        byte[] key =
        {
            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
            0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
        };
        using var aes = Aes.Create();
        var iv     = aes.IV;
        var result = Cryptography.Encryption.EncryptStringToBytes(server.Password, key, iv);

        server.Password = Convert.ToBase64String(result);
        server.IV       = Convert.ToBase64String(iv);

        return(server);
    }
Exemplo n.º 23
0
    private EmailServer Decrypt(EmailServer server)
    {
        // TODO: Get key from elsewhere
        byte[] key =
        {
            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
            0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
        };

        var iv            = Convert.FromBase64String(server.IV);
        var passwordBytes = Convert.FromBase64String(server.Password);
        var result        = Cryptography.Encryption.DecryptStringFromBytes(passwordBytes, key, iv);

        server.Password = result;
        server.IV       = Encoding.Unicode.GetString(iv);

        return(server);
    }
Exemplo n.º 24
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Strip seconds
            Dinner.Date             = Dinner.Date.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0);
            Dinner.SubscriptionStop = Dinner.SubscriptionStop.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0);

            // Dont allow negative prices
            Dinner.Price = Math.Max(Dinner.Price, 0.0);

            if (Dinner.Date < DateTime.Now.AddDays(Dinner.MIN_DAYS_IN_ADVANCE).SetTime(0, 0))
            {
                ModelState.AddModelError("Dinner.Date", $"Kies een datum minimaal { Dinner.MIN_DAYS_IN_ADVANCE } dagen in de toekomst.");
                return(Page());
            }

            if ((Dinner.Date - Dinner.SubscriptionStop).TotalHours < 24)
            {
                ModelState.AddModelError("Dinner.SubscriptionStop", "Kies een tijd minimaal 24 uur vσσr het diner.");
                return(Page());
            }

            if (Dinner.HasPrice && (string.IsNullOrWhiteSpace(Couple.IBAN)))
            {
                ModelState.AddModelError("Couple.IBAN", "Een bankrekening is verplicht als het evenement geld kost.");
                return(Page());
            }

            if (await Database.CreateDinnerAsync(Dinner, Couple) == null)
            {
                ModelState.AddModelError(nameof(Dinner), "Kan dinner nu niet aanmaken.");
                return(Page());
            }

            EmailServer.SendEmail(Couple.EmailAddress, "Nieuw dinner",
                                  $"Nieuw diner aangemaakt, code: <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Management.EditDinnerModel>( Request.Host, Couple.ID, Couple.AdminCode )}\">Beheer</a>");

            return(Redirect(ModelPath.Get <AwaitEmailModel>()));
        }
Exemplo n.º 25
0
        private EmailServer TestEmailServer(EmailServer data, string email = null)
        {
            try
            {
                data.Status = _deployLogic.TestEmailServerConnection(data, email)
                    ? CommandStatus.TestPassed
                    : CommandStatus.TestFailed;
            }

            catch (SmtpException exception)
            {
                ExceptionHandler.Manage(exception, this, Layer.UILogic);

                data.Status = CommandStatus.TestFailed;
                _log.ErrorFormat("Test Failed.");
            }

            return(data);
        }
Exemplo n.º 26
0
        private static bool SendPasswordResetEmail(string ToEmail, string UserName, string UniqueId)
        {
            bool   issent            = false;
            String EmailTemplatepath = Convert.ToString(System.Web.HttpContext.Current.Server.MapPath("~/html/ForgetPasswordEmailHtmlFile.html"));
            String EmailTemplate     = String.Empty;
            String ResetLink         = System.Web.HttpContext.Current.Request.Url.Host + "/Login/LoginRegistration?uid=" + UniqueId;

            EmailTemplate = Jobsportal.Common.ReadHtmlFile(EmailTemplatepath);
            EmailTemplate = EmailTemplate.Replace("@@UserName@@", UserName);
            EmailTemplate = EmailTemplate.Replace("@@ResetLink@@", ResetLink);
            String MSubject = "Reset Password";

            EmailServer emailconfigdata = EmailServer.GetEmailConfiguration();
            SmtpClient  client          = new SmtpClient();

            client.Port                  = Convert.ToInt32(emailconfigdata.Port);
            client.Host                  = emailconfigdata.Host;
            client.EnableSsl             = emailconfigdata.SSL;
            client.Timeout               = 10000;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential(emailconfigdata.Email, emailconfigdata.Password);

            MailMessage mm = new MailMessage(emailconfigdata.Email, ToEmail, MSubject, EmailTemplate);

            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            mm.Subject    = MSubject;
            mm.Body       = EmailTemplate;
            mm.IsBodyHtml = true;

            try
            {
                client.Send(mm);
                issent = true;
            }
            catch (Exception ex)
            {
                DALError.LogError("Login.SendPasswordResetEmail", ex);
            }
            return(issent);
        }
Exemplo n.º 27
0
        private EmailServer RestoreEmailServer()
        {
            EmailServer emailServer;

            try
            {
                emailServer        = _deployLogic.GetEmailServerConfiguration();
                emailServer.Status = CommandStatus.RestorePassed;
            }
            catch (Exception exception)
            {
                ExceptionHandler.Manage(exception, this, Layer.UILogic);
                emailServer = new EmailServer {
                    Status = CommandStatus.RestoreFailed
                };
                _log.ErrorFormat("Restore Failed.");
            }

            return(emailServer);
        }
Exemplo n.º 28
0
        private static void Main(string[] args)
        {
            int counter = 0;

            EmailServer emailServer;

            do
            {
                if (counter == 0)
                {
                    Console.WriteLine("Smtp Server running !!!");
                    counter++;
                }
                emailServer = new EmailServer(IPAddress.Loopback, 25);
                emailServer.Start();
                while (emailServer.IsThreadAlive)
                {
                    Thread.Sleep(500);
                }
            } while (emailServer != null);
        }
Exemplo n.º 29
0
        public ActionResult ExecuteEmailServerAction(EmailServer data, string emCommand)
        {
            ModelState.Clear();

            EmailServer emailServer = null;

            if (string.IsNullOrEmpty(emCommand))
            {
                return(PartialView("~/Areas/UserManagementUI/Views/Deployment/EmailServerPartial.cshtml",
                                   new EmailServer()));
            }

            switch (emCommand)
            {
            case "Test":
            {
                emailServer = TestEmailServer(data);
            }
            break;

            case "Save":
            {
                emailServer = SaveEmailServer(data);
            }

            break;

            case "Restore":
            {
                emailServer = RestoreEmailServer();
            }
            break;
            }

            return(Request.IsAjax()
                ? (ActionResult)
                   PartialView("~/Areas/UserManagementUI/Views/Deployment/EmailServerPartial.cshtml", emailServer)
                : (ActionResult)
                   View("~/Areas/UserManagementUI/Views/Deployment/EmailServerPartial.cshtml", emailServer));
        }
Exemplo n.º 30
0
        public JsonResult ResetPassword(int id)
        {
            Message msg = new Message();

            SysUser sysuser         = unitOfWork.sysUsersRepository.GetByID(id);
            string  password        = CommonTools.GenerateRandomNumber(8);
            string  confirmpassword = CommonTools.ToMd5(password);
            string  sysemail        = sysuser.SysEmail;

            sysuser.SysPassword = confirmpassword;



            if (ModelState.IsValid)
            {
                unitOfWork.sysUsersRepository.Update(sysuser);
                unitOfWork.Save();
                string      EmailContent = "密码已经被重置为" + password.ToString() + ",并已经发送邮件到" + sysuser.SysEmail + ",请注意查收!";
                EmailServer server       = new EmailServer();
                Setting     setting      = unitOfWork.settingsRepository.GetByID(1);
                server.EmailAddress  = setting.EmailFrom;
                server.EmailPassword = setting.EmailPassword;
                server.SMTPClient    = setting.EmailHost;
                EmailEntity mailEntity = new EmailEntity();
                mailEntity.DisplayName = "星星家庭训练系统管理员";
                mailEntity.MailContent = EmailContent;
                mailEntity.ToMail      = sysemail;
                mailEntity.MailTitle   = "重置密码邮件";
                mailEntity.FromMail    = server.EmailAddress;
                EmailServices.SendEmail(server, mailEntity);

                //  AdsEmailServices.SendEmail(EmailContent,sysuser.SysEmail);

                msg.MessageStatus = "true";
                msg.MessageInfo   = EmailContent;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }