public IActionResult OnPost(int id = 0) { if (id > 0) { bridgeGreetings = _myDB.Greetings.Find(id); try { // SEND MailMessage Mailer = new MailMessage(); Mailer.To.Add(new MailAddress(bridgeGreetings.toEmail, bridgeGreetings.toName)); Mailer.Subject = bridgeGreetings.subject; Mailer.Body = "<img src = 'http://nicole.wowoco.org/images/happythanksgiving.jpg' />" + bridgeGreetings.fromName + " has a Thanksgiving greeting for you! Visit " + "<a href=\"http://nicole.wowoco.org/read/\"" + bridgeGreetings.ID + ">" + "this site" + "</a>" + " for the full message!"; Mailer.From = new MailAddress(bridgeGreetings.fromEmail, bridgeGreetings.fromName); Mailer.IsBodyHtml = true; using (SmtpClient smtpServer = new SmtpClient()) { smtpServer.EnableSsl = Boolean.Parse(_myConfiguration["Smtp:EnableSs1"]); smtpServer.Host = _myConfiguration["Smtp:Host"]; // CHANGE smtpServer.Port = Int32.Parse(_myConfiguration["Smtp:Port"]); // CHANGE smtpServer.UseDefaultCredentials = Boolean.Parse(_myConfiguration["Smtp:UseDefaultCredentials"]); smtpServer.Send(Mailer); } // DB-RELATED: ASSIGN SEND INFO TO DATABASE bridgeGreetings.sendDate = DateTime.Now.ToString(); bridgeGreetings.sendIP = this.HttpContext.Connection.RemoteIpAddress.ToString(); // DB-RELATED: UPDATE RECORD ON THE DATABASE _myDB.Greetings.Update(bridgeGreetings); _myDB.SaveChanges(); return(RedirectToPage("complete", new { ID = bridgeGreetings.ID })); } catch { Message = "Apologies, there was an error and your greeting can't be sent."; } } return(Page()); }
public IActionResult OnPost(int id = 0) { if (id > 0) { bridgeMyContact = _myDB.MyContact.Find(id); try { // SEND MailMessage Mailer = new MailMessage(); Mailer.Subject = bridgeMyContact.Subject; Mailer.Body = bridgeMyContact.Message; Mailer.From = new MailAddress(bridgeMyContact.Email, bridgeMyContact.Name); Mailer.IsBodyHtml = true; using (SmtpClient smtpServer = new SmtpClient()) { smtpServer.EnableSsl = true; smtpServer.Host = "smtp.ado-design.com"; // CHANGE smtpServer.Port = 143; // CHANGE smtpServer.UseDefaultCredentials = false; smtpServer.Send(Mailer); } // DB-RELATED: ASSIGN SEND INFO TO DATABASE bridgeMyContact.sendDate = DateTime.Now.ToString(); bridgeMyContact.sendIP = this.HttpContext.Connection.RemoteIpAddress.ToString(); // DB-RELATED: UPDATE RECORD ON THE DATABASE _myDB.MyContact.Update(bridgeMyContact); _myDB.SaveChanges(); return(RedirectToPage("Thankyou")); } catch { Message = "Oops, your message was not sent."; } } return(Page()); }