/// <summary> /// Send the Email /// </summary> /// <param name="model">Mail to Send</param> /// <returns>Operation</returns> public Operation SendMail(MailModel model) => Operation.Try(() => { CacheTemplates(); var modelType = model.GetType(); var mail = new ElasticemailMessage { From = new MailAddress(model.From), Subject = model.Subject.ThrowIfNull("invalid mail subject"), IsBodyHtml = true, Body = Engine.Razor.Run(MailModelTemplateSource.TemplateName(modelType), modelType, model), }; model.Recipients.ForAll((_cnt, _r) => mail.To.Add(new MailAddress(_r))); new ElasticemailWebApi(_apikey) .Send(mail) .ThrowIf(_r => _r.ResultType == ResultType.Error, _r => new Exception(_r.ErrorMessage)); });
private void ForEachString(MailModel source, MailModel destination, Func <string, string> memberFunc) { var propertyQuery = source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(x => x.PropertyType == typeof(string)); if (true) { propertyQuery = propertyQuery.Where(x => x.Name != nameof(MailModel.Password)); } var properties = propertyQuery.ToList(); properties.ForEach(x => { if (x.GetValue(source) is string value) { x.SetValue(destination, memberFunc(value)); } }); }