public ActionResult UploadFile(HttpPostedFileBase file) { if (Extra.IsValidFile(file)) { if (Session[AsyncMailsController.FILES] == null) { Session[AsyncMailsController.FILES] = new List <ExtraFile>(); } if (((List <ExtraFile>)Session[AsyncMailsController.FILES]).Any(x => x.Size == file.ContentLength && x.Name == file.FileName)) { return(Json(new { success = false, message = "El archivo seleccionado ya se encuentra adjuntado." }, JsonRequestBehavior.AllowGet)); } ExtraFile attachment = new ExtraFile(); attachment.Name = file.FileName; attachment.Size = file.ContentLength; attachment.Type = file.ContentType; attachment.Path = Extra.SaveToFS(file); //el contenido va a disco attachment.Id = Path.GetFileName(attachment.Path).Substring(0, 16); attachment.Content = new byte[file.ContentLength]; ((List <ExtraFile>)Session[AsyncMailsController.FILES]).Add(attachment); return(Json(new { success = true, id = attachment.Id }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "El archivo seleccionado es mayor a 5mb o es potencialmente danino." }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Initializes a new instance of the <see cref="RadarrClient" /> class. /// </summary> /// <param name="host">The host.</param> /// <param name="port">The port.</param> /// <param name="apiKey">The API key.</param> /// <param name="urlBase">The URL base.</param> /// <param name="useSsl">if set to <c>true</c> [use SSL].</param> public RadarrClient(string host, int port, string apiKey, [Optional] string urlBase, [Optional] bool useSsl) { // Initialize properties Host = host; Port = port; ApiKey = apiKey; UrlBase = urlBase; UseSsl = useSsl; // Set API URL var sb = new StringBuilder(); sb.Append("http"); if (UseSsl) { sb.Append("s"); } sb.Append($"://{host}:{Port}"); if (UrlBase != null) { sb.Append($"/{UrlBase}"); } sb.Append("/api"); ApiUrl = sb.ToString(); // Initialize endpoints Calendar = new Calendar(this); Command = new Command(this); Diskspace = new Diskspace(this); History = new History(this); Movie = new Movie(this); SystemStatus = new SystemStatus(this); Profile = new Profile(this); Wanted = new Wanted(this); Log = new Log(this); Queue = new Queue(this); Release = new Release(this); QualityDefinition = new QualityDefinition(this); Indexer = new Indexer(this); Restriction = new Restriction(this); Blacklist = new Blacklist(this); Notification = new Notification(this); RootFolder = new RootFolder(this); Config = new Config(this); ExtraFile = new ExtraFile(this); CustomFormat = new CustomFormat(this); }
public ActionResult SendEmail(MailSentViewModel sendInfo, Int64 mailAccountId = 0) { try { if (sendInfo.ToAddress == null) { throw new InvalidRecipientsException("No se escribieron destinatarios"); } MailAccount mailAccount = this.GetMailAccount(mailAccountId); List <ExtraFile> uploadedFiles = new List <ExtraFile>(); if (sendInfo.AttachmentsIds != null && sendInfo.AttachmentsIds.Count > 0 && Session[AsyncMailsController.FILES] != null && ((List <ExtraFile>)Session[AsyncMailsController.FILES]).Count > 0) { foreach (String attachmentId in sendInfo.AttachmentsIds) { ExtraFile file = ((List <ExtraFile>)Session[AsyncMailsController.FILES]).First(x => x.Id == attachmentId); try { using (FileStream fileStream = System.IO.File.Open(file.Path, FileMode.Open, FileAccess.Read)) fileStream.Read(file.Content, 0, (int)file.Size); uploadedFiles.Add(file); } catch (Exception exc) { if (!(exc is UnauthorizedAccessException) && !(exc is DirectoryNotFoundException)) { throw; } } } } mailAccount.SendMail(sendInfo.ToAddress, sendInfo.Body, sendInfo.Subject, uploadedFiles); Session.Remove(AsyncMailsController.FILES); this.ClearTempDirectory(); return(Json(new { success = true, address = sendInfo.ToAddress }, JsonRequestBehavior.AllowGet)); } catch (InvalidRecipientsException exc) { return(Json(new { success = false, message = "No se pudo enviar el email porque alguna de las direcciones de los destinatarios es inexistente. Por favor corríjalos e intentelo de nuevo.", address = sendInfo.ToAddress }, JsonRequestBehavior.AllowGet)); } catch (SmtpException exc) { Log.LogException(exc, "Parametros del mail a enviar: subjectMail(" + sendInfo.Subject + "), addressMail(" + sendInfo.ToAddress + ")."); return(Json(new { success = false, message = "Actualmente tenemos problemas para enviar el email, por favor intételo de nuevo más tarde", address = sendInfo.ToAddress }, JsonRequestBehavior.AllowGet)); } catch (GlimpseException exc) { return(Json(new { success = false, message = exc.GlimpseMessage, address = exc.GlimpseMessage }, JsonRequestBehavior.AllowGet)); } catch (Exception exc) { Session.Remove(AsyncMailsController.FILES); Log.LogException(exc, "Parametros de la llamada: subjectMail(" + sendInfo.Subject + "), addressMail(" + sendInfo.ToAddress + ")."); return(Json(new { success = false, message = "Actualmente tenemos problemas para enviar el email, por favor inténtelo de nuevo más tarde", address = sendInfo.ToAddress }, JsonRequestBehavior.AllowGet)); } }