/// <summary> /// Fixed: /// </summary> public static string Send(IContext context, string reference, long id) { var ss = SiteSettingsUtilities.GetByReference( context: context, reference: reference, referenceId: id); if (context.ContractSettings.Mail == false) { return(Error.Types.Restricted.MessageJson(context: context)); } var outgoingMailModel = new OutgoingMailModel( context: context, reference: reference, referenceId: id); var invalidMailAddress = string.Empty; var invalid = OutgoingMailValidators.OnSending( context: context, ss: ss, outgoingMailModel: outgoingMailModel, data: out invalidMailAddress); switch (invalid) { case Error.Types.None: break; case Error.Types.BadMailAddress: case Error.Types.ExternalMailAddress: return(invalid.MessageJson( context: context, data: invalidMailAddress)); default: return(invalid.MessageJson(context: context)); } var error = outgoingMailModel.Send( context: context, ss: ss); return(error.Has() ? error.MessageJson(context: context) : new OutgoingMailsResponseCollection(outgoingMailModel) .CloseDialog() .ClearFormData() .Html("#OutgoingMailDialog", string.Empty) .Val("#OutgoingMails_Title", string.Empty) .Val("#OutgoingMails_Body", string.Empty) .Prepend( "#OutgoingMailsForm", new HtmlBuilder().OutgoingMailListItem( context: context, ss: ss, outgoingMailModel: outgoingMailModel)) .Message(Messages.MailTransmissionCompletion(context: context)) .ToJson()); }
/// <summary> /// Fixed: /// </summary> public static string Send(string reference, long id) { if (!Contract.Mail()) { return(Error.Types.Restricted.MessageJson()); } var outgoingMailModel = new OutgoingMailModel(reference, id); var invalidMailAddress = string.Empty; var invalid = OutgoingMailValidators.OnSending( SiteSettingsUtilities.GetByReference(reference, id), outgoingMailModel, out invalidMailAddress); switch (invalid) { case Error.Types.None: break; case Error.Types.BadMailAddress: case Error.Types.ExternalMailAddress: return(invalid.MessageJson(invalidMailAddress)); default: return(invalid.MessageJson()); } var error = outgoingMailModel.Send(); return(error.Has() ? error.MessageJson() : new OutgoingMailsResponseCollection(outgoingMailModel) .CloseDialog() .ClearFormData() .Html("#OutgoingMailDialog", string.Empty) .Val("#OutgoingMails_Title", string.Empty) .Val("#OutgoingMails_Body", string.Empty) .Prepend("#OutgoingMailsForm", new HtmlBuilder().OutgoingMailListItem( outgoingMailModel, selector: "#ImmediatelyAfterSending" + outgoingMailModel.OutgoingMailId)) .Message(Messages.MailTransmissionCompletion()) .ToJson()); }
/// <summary> /// Fixed: /// </summary> public static System.Web.Mvc.ContentResult SendByApi(Context context, string reference, long id) { var itemModel = new ItemModel( context: context, referenceId: id); var siteModel = new SiteModel( context: context, siteId: itemModel.SiteId); var ss = SiteSettingsUtilities.Get( context: context, siteModel: siteModel, referenceId: itemModel.ReferenceId); var outgoingMailModel = new OutgoingMailModel( context: context, reference: reference, referenceId: id); var data = context.RequestDataString.Deserialize <OutgoingMailApiModel>(); if (data == null) { return(ApiResults.Get(ApiResponses.BadRequest(context: context))); } if (!siteModel.WithinApiLimits()) { return(ApiResults.Get(ApiResponses.OverLimitApi( context: context, siteId: itemModel.SiteId, limitPerSite: Parameters.Api.LimitPerSite))); } if (data.From != null) { outgoingMailModel.From = new System.Net.Mail.MailAddress(data.From); } if (data.To != null) { outgoingMailModel.To = data.To; } if (data.Cc != null) { outgoingMailModel.Cc = data.Cc; } if (data.Bcc != null) { outgoingMailModel.Bcc = data.Bcc; } if (data.Title != null) { outgoingMailModel.Title = new Title(data.Title); } if (data.Body != null) { outgoingMailModel.Body = data.Body; } var invalid = OutgoingMailValidators.OnSending( context: context, ss: ss, outgoingMailModel: outgoingMailModel); switch (invalid.Type) { case Error.Types.None: break; default: return(ApiResults.Error( context: context, errorData: invalid)); } var errorData = outgoingMailModel.Send( context: context, ss: ss); switch (errorData.Type) { case Error.Types.None: SiteUtilities.UpdateApiCount(context: context, ss: ss); return(ApiResults.Success( id: id, limitPerDate: Parameters.Api.LimitPerSite, limitRemaining: Parameters.Api.LimitPerSite - ss.ApiCount, message: Displays.MailTransmissionCompletion( context: context, data: outgoingMailModel.Title.DisplayValue))); default: return(ApiResults.Error( context: context, errorData: errorData)); } }