Пример #1
0
        public void SendMessage(IContestEntrant winner)
        {
            string      messageBody = FirstName + " " + LastName + ",\n unfortuantely, " + winner.GetName() + " won the sweepstakes.";
            MimeMessage message     = new MimeMessage();

            message.From.Add(new MailboxAddress("Sweepstakes Manager", "*****@*****.**"));
            message.To.Add(new MailboxAddress(GetName(), GetEmailAddress()));
            message.Subject = "Sweepstakes Entry";
            message.Body    = new TextPart("plain")
            {
                Text = messageBody
            };

            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("smtp.gmail.com", 587);

                // Note: only needed if the SMTP server requires authentication
                client.Authenticate("*****@*****.**", "TestAccount1994");

                client.Send(message);
                client.Disconnect(true);
            }
        }
Пример #2
0
        public string PickWinner()
        {
            int             randomNumber = rand.Next(0, entries.Count);
            IContestEntrant winner       = entries.ElementAt(randomNumber).Value;

            entries.Remove(winner.GetRegistration());
            WinningContestant winningContestant = new WinningContestant(winner.GetFirstName(), winner.GetLastName(), winner.GetEmailAddress(), winner.GetRegistration());

            entries.Add(winningContestant.GetRegistration(), winningContestant);
            for (int i = 0; i < entries.Count; i++)
            {
                entries.ElementAt(i).Value.SendMessage(winningContestant);
            }
            return(entries.ElementAt(randomNumber).Value.GetEmailAddress());
        }