public void AddAttachment_Throws_Exception_If_Filename_Already_Exists() { var target = new ElasticemailMessage(); target.AddAttachment("file1.txt", new byte[100]); target.AddAttachment("file1.txt", new byte[200]); }
public void AddAttachment() { var target = new ElasticemailMessage(); target.AddAttachment("file1.txt", new byte[100]); target.AddAttachment("file2.txt", new byte[200]); Assert.AreEqual(2, target.Attachments.Count); }
public void AddAttachment() { var target = new ElasticemailMessage(); target.AddAttachment("file1.txt", new byte[100]); target.AddAttachment("file2.txt", new byte[200]); Assert.AreEqual(2, target.Attachments.Count); }
public void ErrorMessage_If_To_Address_Is_Missing() { var target = new ElasticemailWebApi(_apiKey); var mail = new ElasticemailMessage(); mail.From = new MailAddress("*****@*****.**", "John"); var actual = target.Send(mail); Assert.AreEqual(ResultType.Error, actual.ResultType); Assert.IsTrue(actual.ErrorMessage.Contains("recipient address is missing")); }
public void SendUnauthorized() { var target = new ElasticemailWebApi("invalidApiKey"); var mail = new ElasticemailMessage(); mail.From = new MailAddress("*****@*****.**", "John"); mail.To.Add(new MailAddress("*****@*****.**", "Anna")); var actual = target.Send(mail); Assert.AreEqual(ResultType.Error, actual.ResultType); Assert.IsTrue(actual.ErrorMessage.Contains("Unauthorized")); }
public void Send_Email_Returns_TransactionId() { var target = new ElasticemailWebApi(_apiKey); var mail = new ElasticemailMessage(); mail.To.Add(new MailAddress("*****@*****.**")); mail.From = new MailAddress("*****@*****.**", "Marc"); mail.ReplyTo = new MailAddress("*****@*****.**", "Marc"); mail.Subject = "Test"; mail.Body = "Body"; var actual = target.Send(mail); Assert.AreEqual(ResultType.Success, actual.ResultType); Assert.IsNotNull(actual.TransactionId); }
public void Send_Email_With_Attachment() { var target = new ElasticemailWebApi(_apiKey); var mail = new ElasticemailMessage(); mail.To.Add(new MailAddress("*****@*****.**", "Marc")); mail.From = new MailAddress("*****@*****.**", "Marc"); mail.ReplyTo = new MailAddress("*****@*****.**", "Marc"); mail.Subject = "Test"; mail.Body = "Body"; mail.AddAttachment("file.txt", new byte[100]); mail.AddAttachment("file2.txt", new byte[200]); var actual = target.Send(mail); Assert.AreEqual(ResultType.Success, actual.ResultType); Assert.IsNotNull(actual.TransactionId); }
/// <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)); });
public async Task SendMaill() { //DateTime.Now.AddDays(-1); //Transaction trans = new Transaction(); var activeLoan = _context.Loans.Where(c => c.IsActive == true).ToList(); _emailSettings.FromName = _configuration.GetValue <string>("ElasticEmail:FromName"); _emailSettings.From = _configuration.GetValue <string>("ElasticEmail:From"); _emailSettings.ApiKey = _configuration.GetValue <string>("ElasticEmail:ApiKey"); SupperAccount amount = _context.SupperAccounts.First(c => c.SupperAcctNumber == "1234567890"); if (activeLoan.Any()) { var dict = new Dictionary <string, string> { { "apikey", _emailSettings.ApiKey }, { "from", _emailSettings.From }, { "fromName", _emailSettings.FromName }, { "isTransactional", "true" } }; foreach (var item in activeLoan) { Transaction trans = new Transaction(); var ifExists = _context.SupperAccounts.SingleOrDefault(c => c.LoanId == item.LoanId && c.TransactDate == DateTime.Now.ToString("yyyy-MM-dd")); // var ifExists = _context.SupperAccounts.SingleOrDefault(c => c.LoanId == item.LoanId && c.TransactDate == DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")); // var ifExists = _context.SupperAccounts.SingleOrDefault(c => c.LoanId == item.LoanId && trans.Tr_Date == DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")); if (ifExists == null) { // SupperAccount amount = _context.SupperAccounts.First(c => c.SupperAcctNumber == "1234567890"); decimal addAmount = 0; SupperAccount supper = new SupperAccount(); // Transaction trans = new Transaction(); if (item.Loan_Amount_Paid >= 4000) { if (item.Loan_Amount_Paid > 4000) { item.Loan_Amount_Paid = item.Loan_Amount_Paid - 4000; addAmount = 4000; // doing this will update a single role // amount.Amount = amount.Amount + Convert.ToDecimal(addAmount); //if (supper.LoanId == 0 /*&& supper.TransactDate == DateTime.Now.ToString("yyyy-MM-dd")*/) //{ // //doing this will update on a different role for each individual supper.Amount = supper.Amount + Convert.ToDecimal(addAmount); supper.SupperAcctNumber = amount.SupperAcctNumber; supper.SupperPhone = amount.SupperPhone; supper.SupperEmail = amount.SupperEmail; supper.LoanId = item.LoanId; supper.TransactDate = DateTime.Now.ToString("yyyy-MM-dd"); // supper.CustAcctNumber = item.AccountNumber; _context.SupperAccounts.Add(supper); } else if (item.Loan_Amount_Paid == 4000) { supper.Amount = 0; supper.LoanId = 0; supper.Amount = supper.Amount + Convert.ToDecimal(item.Loan_Amount_Paid); supper.SupperAcctNumber = amount.SupperAcctNumber; supper.SupperEmail = amount.SupperEmail; supper.SupperPhone = amount.SupperPhone; supper.LoanId = item.LoanId; supper.TransactDate = DateTime.Now.ToString("yyyy-MM-dd"); // supper.TransactDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //supper.TransactDate = DateTime.Now.ToString("hh:mm tt"); item.Loan_Amount_Paid = item.Loan_Amount_Paid - 4000; //Transaction trans = new Transaction(); //trans.Amount = item.Loan_Amount_Paid; ////trans.Amount = addAmount; //trans.AccountNumber = item.AccountNumber; //trans.Date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); //trans.Type = "Admin"; //_context.Transactions.Add(trans); _context.SupperAccounts.Add(supper); //await _context.Saved(); } else { throw new Exception("Amount Invalid"); } } else if (item.Loan_Amount_Paid < 4000) { // break; // if the account is zero when the customer is active } await _context.Saved(); var mbody = new ElasticemailMessage(); dict.TryAdd("to", amount.SupperEmail); mbody.Subject = "creaded loan"; dict.TryAdd("amount", Convert.ToString(amount.Amount)); dict.TryAdd("accountNumber", amount.CustAcctNumber); mbody.IsBodyHtml = true; //string address = "https://api.elasticemail.com/v2/email/send"; string address = _emailSettings.Url; using (HttpClient client = new HttpClient()) { var formContent = new FormUrlEncodedContent(dict); var apiResponse = await client.PostAsync(address, formContent); apiResponse.EnsureSuccessStatusCode(); if (apiResponse != null) { // item.IsSent = true; } // await _context.Saved(); await _context.Saved(); await apiResponse.Content.ReadAsStringAsync(); } } } } }
public void AddAttachment_Throws_Exception_If_File_Not_Found() { var target = new ElasticemailMessage(); target.AddAttachment(@"C:\notExistingFile.txt"); }
public void AddAttachment_Throws_Exception_If_Filename_Already_Exists() { var target = new ElasticemailMessage(); target.AddAttachment("file1.txt", new byte[100]); target.AddAttachment("file1.txt", new byte[200]); }
public void AddAttachment_Throws_Exception_If_File_Not_Found() { var target = new ElasticemailMessage(); target.AddAttachment(@"C:\notExistingFile.txt"); }