Exemplo n.º 1
0
        protected void btnReplyAd_ServerClick(object sender, EventArgs e)
        {
            AdService.AdCRUDClient adService = new AdService.AdCRUDClient();
            adService.Open();
            String[] userdetails = adService.getUserEmail(adnum);
            adService.Close();

            if (txtName.Value == "" || txtemail.Value == "" || txtMessage.Value == "")
            {
                replysentdiv.InnerHtml = "<p class='red-text'>Please fill in all the appropriate fields</p>";
            }
            else
            {
                NetworkCredential netCred = new NetworkCredential("*****@*****.**", "IFMTYP2016");
                SmtpClient        smtpobj = new SmtpClient("smtp.gmail.com", 587);
                smtpobj.EnableSsl   = true;
                smtpobj.Credentials = netCred;
                //smtpobj.DeliveryMethod = SmtpDeliveryMethod.Network;

                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress("*****@*****.**", "twoGames");
                mailMessage.To.Add(new MailAddress(userdetails[0]));
                mailMessage.Subject    = "You have a reply to your ad \"" + (string)adDetails[1] + "\"";
                mailMessage.IsBodyHtml = true;

                mailMessage.Body  = "<h1>Hi " + userdetails[1] + ",</h1><br/>";
                mailMessage.Body += "<b>" + txtName.Value + "</b> has replied to your advert <b>\"" + (string)adDetails[1] + "\"</b>";
                mailMessage.Body += "<br/><br/>";
                mailMessage.Body += "Their message: <br/>";
                mailMessage.Body += "\"<i>" + txtMessage.Value + "</i>\"";
                mailMessage.Body += "<br/><br/><a href='mailto:" + txtemail.Value + "?subject=[twoGames] \"" + (string)adDetails[1] + "\" Advert'><button>Click here to reply</button></a>";
                mailMessage.Body += "<br/><br/>Kind Regards<br/>twoGames";



                try
                {
                    smtpobj.Send(mailMessage);
                    btnReplyAd.Visible     = false;
                    replysentdiv.InnerHtml = "<p>Your message has been sent successfully.</p>";
                }
                catch (SmtpException ex)
                {
                    replysentdiv.InnerHtml = "<p class='red-text'>Failed to send your message. Please try again.</p>";
                }
            }
        }