public static T ToEnum <T>(this string strEnum) { T t = default(T); try { t = (T)Enum.Parse(typeof(T), strEnum); } catch (Exception ex) { Debuging.Warning(ex, "Class: Utility, Method: ToEnum cannot cast the strEnum = " + strEnum + " To Enum "); } return(t); }
public static ActionResult SendEmail(string smtpHost, string from, string to, string body, string subject, string fromPassword) { ActionResult result = new ActionResult(); try { if (!IsValidEmail(to) || !IsValidEmail(@from)) { throw new LocalException("EmailAddress is wrong", "آدرس ایمیل صحیح نیست", "toEmailAddress", to, "fromEmailAddress", @from); } MailMessage message = new MailMessage(@from, to, subject, body) { BodyEncoding = Encoding.UTF8, IsBodyHtml = true, DeliveryNotificationOptions = DeliveryNotificationOptions.None, Priority = MailPriority.High, SubjectEncoding = Encoding.UTF8 }; SmtpClient client = new SmtpClient(smtpHost); //example:"mto-foods.ir" client.Credentials = new NetworkCredential(@from, fromPassword); client.Send(message); result.IsSuccess = true; result.ResultMessage = MessageText.SUCCESS; } catch (LocalException ex) { Debuging.Warning(ex, "SendEmail Function"); result.IsSuccess = false; result.EnglishMessage = ex.Message; result.ResultMessage = ex.ResultMessage; } catch (Exception ex) { ex.Data.Add("From", @from); ex.Data.Add("To", to); ex.Data.Add("Body", body); ex.Data.Add("Subject", subject); Debuging.Error(ex, "SendEmail Function"); result.IsSuccess = false; result.EnglishMessage = ex.Message; result.ResultMessage = MessageText.UNKNOWN_ERROR; } return(result); }