public async Task <IActionResult> Iletisim()
        {
            contactViewModel contact = new contactViewModel();

            contact.maps = await _context.maps.ToListAsync();

            contact.adresses = await _context.adresses.ToListAsync();

            contact.mails = await _context.Mail.ToListAsync();

            contact.phones = await _context.phone.ToListAsync();

            return(View(contact));
        }
        public ActionResult Contact(contactViewModel model)
        {
            if (ModelState.IsValid)
            {
                var         body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                MailMessage mail = new MailMessage();
                mail.To.Add("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.From    = new MailAddress("*****@*****.**");
                mail.Subject = "Comments and Thoughts";



                mail.IsBodyHtml = true;

                mail.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
                // message.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential
                                                 ("*****@*****.**", "fall2015cmps285");// Enter senders User name and password
                smtp.EnableSsl = true;
                Console.WriteLine("Sending email .... ");
                smtp.Send(mail);


                return(View("ContactSuccess"));
            }

            else
            {
                return(View("Index"));
            }
        }
Example #3
0
        public ActionResult Contact(contactViewModel cvm)
        {
            //when a class has validation attributes, that validation should be
            //checked BEFORE attempting to process any data.
            if (!ModelState.IsValid)
            //if(ModelState.IsValid == false)
            {
                //send them back to the form, by passing the object to the view,
                //the form returns with the original populated information.
                return(View(cvm));
            }
            //Only executes if the form (object) passes model validation
            //build the Message - what we see when we receive the email
            string message = $"You have received an email from {cvm.Name} with a subject " +
                             $"{cvm.Message}. Please respond to {cvm.EmailAdress} with your response to " +
                             $"the following message: <br />{cvm.Message}";

            //MailMessage (what sends the email) - System.Net.Mail
            MailMessage mm = new MailMessage(
                //FROM
                "*****@*****.**",
                //TO - this assumes forwarding by the host
                //"*****@*****.**",//could be [email protected] or whatever addy you wish
                "*****@*****.**", //hard code until SmarterASP works around the forwarding issue
                                       //SUBJECT
                "From Website: " + cvm.Message,
                //BODY
                message);

            //MailMessage properties
            //Allow HTML formatting in the email (message has HTML in it)
            mm.IsBodyHtml = true;
            //if you want to mark these emails with high priority
            mm.Priority = MailPriority.High; //the default is Normal
                                             //respond to the sender's email instead our own SMTP Client (webmail)
            mm.ReplyToList.Add(cvm.EmailAdress);

            //SmtpClient - This is the information from the HOST (smarterAsp.net)
            //that allows the email to actually be sent.
            SmtpClient client = new SmtpClient("mail.quintindublin.com");

            //client credentials (smarterASP requires your user name and password)
            client.Credentials = new NetworkCredential("*****@*****.**",
                                                       "P@ssw0rd");

            //It is possible that the mailserver is down or we may have configuration
            //issues, so we want to encapsulate our code in a try/catch
            try
            {
                //attempt to send email
                client.Send(mm);
            }
            catch (Exception ex)
            {
                ViewBag.CustomerMessage =
                    $"We're sorry your request could not be completed at this time." +
                    $" Please try again later. Error Message: <br /> {ex.Message}";
                return(View(cvm));
                //return the view WITH the entire message so that users can copy/paste
                //it for later.
            }
            //if all goes will return a view that displays a confirmation to the end user
            //that the email was sent.
            return(View("EmailConfirmation", cvm));
        }