diff --git a/Controllers/RegistrazioniController.cs b/Controllers/RegistrazioniController.cs index 4dbaa6a..a791a16 100644 --- a/Controllers/RegistrazioniController.cs +++ b/Controllers/RegistrazioniController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using NuGet.Protocol.Plugins; using System.Diagnostics; +using System.Net.Mail; +using System.Net; using System.Reflection; using System.Text; using VirtualTask.Models; @@ -116,7 +119,6 @@ namespace VirtualTask.Controllers { urlBase = apiUrl + "registrazioni/add"; - //urlBase = "http://10.0.0.187:8000/api/Polo/registrazioni/add"; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); client.BaseAddress = baseAddress; @@ -127,6 +129,8 @@ namespace VirtualTask.Controllers if (response.IsSuccessStatusCode) { + //mando mail avvenuta richiesta + bool esito = MailSent(model.email); return RedirectToAction("RegistrazioneOk"); } else @@ -386,6 +390,52 @@ namespace VirtualTask.Controllers } return bAziPres; } + private bool MailSent(string receiver) + { + //REMEMBER per una mail gmail bisogna andare nelle impostazioni + //e impostare "Accesso app meno sicure" a ON + bool sent = false; + + string senderMail = _configuration["ApplicationInsights:mittenteMail"]; + string senderName = _configuration["ApplicationInsights:nomeMail"]; + string pwdMail = _configuration["ApplicationInsights:pwdMail"]; + + + string subject = _configuration["ApplicationInsights:subjectMail"]; + string message = getMailText(); + + var senderEmail = new MailAddress(senderMail, senderName); + var receiverEmail = new MailAddress(receiver, "Receiver"); + var password = pwdMail; + var sub = subject; + var body = message; + var smtp = new SmtpClient + { + Host = "smtp.gmail.com", + Port = 587, + EnableSsl = true, + + DeliveryMethod = SmtpDeliveryMethod.Network, + UseDefaultCredentials = false, + Credentials = new NetworkCredential(senderEmail.Address, password) + }; + using (var mess = new MailMessage(senderEmail, receiverEmail) + { + Subject = subject, + Body = body + }) + { + smtp.Send(mess); + } + return sent; + } + + private string getMailText() + { + string txt = string.Empty; + txt = "contenuto mail di registrazione"; + return txt; + } } diff --git a/Views/CommesseVT/Create.cshtml b/Views/CommesseVT/Create.cshtml index 91aa5cb..528f62d 100644 --- a/Views/CommesseVT/Create.cshtml +++ b/Views/CommesseVT/Create.cshtml @@ -19,23 +19,27 @@ @Html.HiddenFor(x => x.latipcli)
+
 
+
 
@* @Html.DropDownListFor(x => x.lacodcli,(IEnumerable)ViewBag.Anag, new{@class = "form-control"})*@ +
@Html.DropDownListFor(x => x.lacodcli, (IEnumerable)ViewBag.Anag, "--Seleziona un cliente--", new { @id="ddlClienti",@class = "form-control"})
 
@* @Html.DropDownListFor(x => x.lacodimp,(IEnumerable)ViewBag.Impianti, new{@class = "form-control"})*@ +
@Html.DropDownListFor(x => x.lacodimp, new List(), "--Seleziona un impianto--", new { @id="ddlImpianti",@class = "form-control"})
diff --git a/appsettings.json b/appsettings.json index a247ddf..8c23815 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,7 +6,11 @@ } }, "ApplicationInsights": { - "rootUrlApi": "https://api.poloinformatico.it:9000/api/Polo/" + "rootUrlApi": "https://api.poloinformatico.it:9000/api/Polo/", + "mittenteMail": "audiffredi@poloinformatico.it", + "nomeMail": "Supporto Virtual Task", + "pwdMail": "audicruz70", + "subjectMail": "Richiesta App di test" }, "AllowedHosts": "*" }