public static MailBL GetInstance() { if (instance == null) { instance = new MailBL(); } client = new SmtpClient(Settings.Default.Mail_Server, Settings.Default.Mail_Port); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.EnableSsl = true; fromAddress = new MailAddress(Settings.Default.Mail_Address, "AYMK Coin Order Management System", Encoding.UTF8); return(instance); }
public void SendMail(AlertResponse response, NotificationTitleType type, decimal percentange = 0) { Notification n = new Notification(); n.Id = ObjectId.GenerateNewId(); n.Style = NotificationStyles.INFO.ToString(); n.AccountId = response.Id; n.CreatedAt = DateTime.UtcNow; if (type == NotificationTitleType.PRICE_ABOWE || type == NotificationTitleType.PRICE_BELOW) { n.Message = string.Format("Exchange: {4}{0}Market: {5}{0}{0}Above Price: {1}{0}Saved Price: {2}{0}Below Price: {3}{0}{0}Current Price:{7}{0}{0}Date: {6:dd.MM.yyyy HH:mm} UTC", Environment.NewLine, response.Alert.AboveValue, response.Alert.SavedValue, response.Alert.BelowValue, response.Exchange.ExchangeName, response.Market.Code, DateTime.UtcNow, response.Market.Ticker.Last); } else if (type == NotificationTitleType.PERCENTANGE_ABOWE || type == NotificationTitleType.PERCENTANGE_BELOW) { n.Message = string.Format("Exchange: {4}{0}Market: {5}{0}Above Percent: % {1:0.00}{0}Saved Price: {2}{0}Below Percent: % {3:0.00}{0}{0}Current Price:{8}{0}Percentange:% {7:0.00}{0}{0}Date: {6:dd.MM.yyyy HH:mm} UTC", Environment.NewLine, response.Alert.AboveValue, response.Alert.SavedValue, response.Alert.BelowValue, response.Exchange.ExchangeName, response.Market.Code, DateTime.UtcNow, percentange, response.Market.Ticker.Last); } n.Title = response.Market.Code + " is " + type.ToString(); n.Type = NotificationTypes.EMAIL.ToString(); n.Repeat = 1; string displayName; if (string.IsNullOrEmpty(response.Name) && string.IsNullOrEmpty(response.Surname)) { displayName = response.Email; } else { displayName = string.Format("{0} {1}", response.Name, response.Surname); } Response mailResponse = MailBL.GetInstance().SendMail(response.Email, n.Title, n.Message, displayName); if (mailResponse.IsSuccess) { n.CompletedAt = DateTime.UtcNow; n.Status = NotificationStatus.SENT.ToString(); n.StatusMessage = mailResponse.Message; } else { n.Status = NotificationStatus.HASERROR.ToString(); n.StatusMessage = mailResponse.Message; } AccountBL.GetInstance().AddNotification(n); Console.WriteLine(n.Title + "---" + DateTime.Now); }