예제 #1
0
 public GuestBookController ()
 {
     if (GRepo == null)
         GRepo = new GuestBookRepository();
 }
예제 #2
0
        public bool Send()
        {
            if (EmailTo == null || EmailFrom == null || Message == null)
                return false;

            MailDefinition md = new MailDefinition();
            md.From = EmailFrom;
            md.Subject = Subject;

            var PlainText = Regex.Replace(Message, "<.*?>", String.Empty);

            MailMessage msg = md.CreateMailMessage(EmailTo, Replacements, PlainText, new System.Web.UI.Control());
            msg.BodyEncoding = Encoding.UTF8;
            msg.SubjectEncoding = Encoding.UTF8;
            msg.From = new MailAddress(EmailFrom, "MB Wedding Mailbot");     //redunant, but mail headers are wonky
            msg.Sender = new MailAddress(EmailFrom, "MB Wedding Mailbot");    //redunant, but mail headers are wonky

            foreach (var Item in CarbonCopy)
            {
                msg.CC.Add(new MailAddress(Item.ToString()));
            }

            foreach (var Item in BlindCarbonCopy)
            {
                msg.Bcc.Add(new MailAddress(Item.ToString()));
            }

            //var MailClient = new SmtpClient();
            //MailClient.PickupDirectoryLocation = @"C:\inetpub\mailroot\Pickup";

            var MailClient = new SmtpClient();
            MailClient.Host = "smtp.1and1.com";
            MailClient.Port = 587;
            MailClient.EnableSsl = true;
            MailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

            var Credentials = new NetworkCredential();
            Credentials.UserName = "******";
            Credentials.Password = "";

            MailClient.UseDefaultCredentials = false;
            MailClient.Credentials = Credentials;

            try
            {
                MailClient.Send(msg);
                MailClient.Dispose();

                return true;
            }
            catch (Exception ex)
            {
                using (var GRepo = new GuestBookRepository())
                {
                    GRepo.WriteLog(ex, "From Email Service");
                }
                MailClient.Dispose();
                return false;
            }
        }