public async Task <IActionResult> Index([FromBody] MailModel mail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool result; try { try { result = await mailGunMailService.Send(mail); } catch (Exception exception) { Debug.WriteLine("There was a problem using primary main API provider. " + exception); result = await sendGridMailService.Send(mail); } } catch (Exception exception) { Debug.WriteLine("There was a problem using secondary main API provider. " + exception); result = false; } var message = result ? "The mail has been sent successfully." : "Something went wrong! try again later."; var response = new MailResponse { Success = result, Message = message }; return(Ok(response)); }
public Guid MailResponse(SendMailResponse request) { CMDataAccess datatAccess = new CMDataAccess(); MailResponse requestData = new MailResponse(); if (request != null) { requestData.RequestGuid = request.RequestGuid; requestData.Token = request.Token; requestData.CreatedDate = DateTime.Now; MailResponseDetails mailresponsedetails = null; foreach (var varItem in request.Details) { mailresponsedetails = new MailResponseDetails(); mailresponsedetails.MailGuid = varItem.MailGuid; mailresponsedetails.To = varItem.To; mailresponsedetails.From = varItem.From; mailresponsedetails.CC = varItem.CC; mailresponsedetails.BCC = varItem.BCC; mailresponsedetails.Status = varItem.Status; mailresponsedetails.ServiceResponse = varItem.ServiceResponse; mailresponsedetails.CreatedDate = DateTime.Now; mailresponsedetails.MailResponse = requestData; requestData.MailResponseDetails.Add(mailresponsedetails); } return(datatAccess.MailResponse(requestData)); } return(Guid.NewGuid()); }
public async Task <MailResponse> GetMailInbox() { string url = WebServiceConstant.MailInbox; AuthenticationHeaderValue token = new AuthenticationHeaderValue("bearer", Settings.GeneralSettings); conection.ClientHttp().DefaultRequestHeaders.Authorization = token; MailResponse response = new MailResponse(); try { var result = await conection.ClientHttp().GetAsync(url); if (result.IsSuccessStatusCode) { string content = await result.Content.ReadAsStringAsync(); if (content != null) { response = JsonConvert.DeserializeObject <MailResponse>(content); response.IsCorrect = true; return(response); } } } catch (Exception ex) { Crashes.TrackError(ex); } return(response); }
public Guid MailResponse(MailResponse item) { var result = default(Guid); using (var db = new RegistrationContext()) { item.MailResponseID = default(int); db.Entry <MailResponse>(item).State = EntityState.Added; db.SaveChanges(); result = item.RequestGuid; } return(result); }
public void backgroundtest(CancellationToken token) { MailResponse mailResponse = new MailResponse(); try { mailResponse.successMailCount = 0; mailResponse.status = "In Progress"; mailResponse.logs = new List <string>(); mailResponse.logs.Add("Started at : " + DateTime.Now.ToString("dd MMM, yyyy hh:mm tt")); for (int i = 0; i < 100; i++) { token.ThrowIfCancellationRequested(); if (i % 2 == 0) { mailResponse.logs.Add("Send at : " + DateTime.Now.ToString("dd MMM, yyyy hh:mm:ss tt")); } else { mailResponse.logs.Add("<span class='text-danger'>Error: Send at : " + DateTime.Now.ToString("dd MMM, yyyy hh:mm:ss tt") + "</span>"); } mailResponse.percentComplete = i; SaveToJson(mailResponse); Thread.Sleep(5000); } mailResponse.logs.Add("end at : " + DateTime.Now.ToString("dd MMM, yyyy hh:mm:ss tt")); mailResponse.status = "Completed"; isMailServiceRunning = false; //Last save SaveToJson(mailResponse); } catch (OperationCanceledException) { mailResponse.status = "Cancelled"; isMailServiceRunning = false; //Last save SaveToJson(mailResponse); } catch (Exception) { mailResponse.status = "Error"; isMailServiceRunning = false; //Last save SaveToJson(mailResponse); } finally { cts = null; } }
public void CancelMailAsync() { if (cts != null) { cts.Cancel(); } MailResponse mailResponse = new MailResponse(); mailResponse.status = "Not Started"; mailResponse.logs = new List <string>(); mailResponse.logs.Add("Not Started"); SaveToJson(mailResponse); }
private MailResponse ArmarEmail() { MailResponse response = new MailResponse(); MailMessage Email = new MailMessage(); SmtpClient smtpMail = new SmtpClient(); try { Email.Subject = request.Subject; Email.To.Add(request.To); Email.Body = request.Body; if (request.IsFile) { foreach (string archivo in request.Files) { if (File.Exists(@archivo)) { Email.Attachments.Add(new Attachment(@archivo)); } } } Email.IsBodyHtml = true; Email.From = new MailAddress(request.From); smtpMail.EnableSsl = request.Configuration.EnableSsl; smtpMail.UseDefaultCredentials = false; smtpMail.Host = request.Configuration.Host; smtpMail.Port = request.Configuration.Port; smtpMail.DeliveryMethod = SmtpDeliveryMethod.Network; smtpMail.Credentials = new NetworkCredential(request.Credentials.Username, request.Credentials.Password); smtpMail.Timeout = 300000; smtpMail.Send(Email); Email.Attachments.Dispose(); Email.Dispose(); smtpMail.Dispose(); response.Exito = true; } catch (Exception ex) { response.Exito = false; response.MensajeError = ex.Message; response.Pila = ex.StackTrace; } return(response); }
/// <summary> /// Enviars the email. /// </summary> /// <param name="request">Los parametros del Email.</param> /// <returns></returns> public MailResponse EnviarEmail(MailRequest request) { MailResponse response = new MailResponse(); this.request = request; response = Validate(); if (!response.Exito) { return(response); } response = ArmarEmail(); return(response); }
private MailResponse Validate() { MailResponse response = new MailResponse(); response.Exito = true; if (string.IsNullOrWhiteSpace(request.Body)) { response.Exito = false; response.MensajeError = "No ingreso el cuerpo del Email"; response.Pila = response.MensajeError; } else if (request.Credentials == null || string.IsNullOrWhiteSpace(request.Credentials.Password) || string.IsNullOrWhiteSpace(request.Credentials.Username)) { response.Exito = false; response.MensajeError = "No se ingreso las credenciales del Emisor"; response.Pila = response.MensajeError; } else if (request.IsFile && request.Files.Count == 0) { response.Exito = false; response.MensajeError = "No existen archivos adjuntos"; response.Pila = response.MensajeError; } else if (string.IsNullOrWhiteSpace(request.From)) { response.Exito = false; response.MensajeError = "No existe el email del Emisor"; response.Pila = response.MensajeError; } else if (string.IsNullOrWhiteSpace(request.Subject)) { response.Exito = false; response.MensajeError = "No existe el asunto del email"; response.Pila = response.MensajeError; } else if (string.IsNullOrWhiteSpace(request.To)) { response.Exito = false; response.MensajeError = "No existe el destinatario(s) del email"; response.Pila = response.MensajeError; } return(response); }
static void Main(string[] args) { //Mails mail = new Mails(); //mail.Subject = "TEST"; //mail.Retries = 1; //mail.From = "*****@*****.**"; //mail.Content = "THIS IS A TEST MESSAGE"; //mail.ApplicationGUID = "B02A6A55E3BD491ABE29E9F3BAC698F8"; //mail.To = new List<string>() { "*****@*****.**","*****@*****.**","*****@*****.**" }; //Mailer.APIKey = "QjAyQTZBNTVFM0JENDkxQUJFMjlFOUYzQkFDNjk4RjgNCg=="; //Mailer.APPId = "B02A6A55E3BD491ABE29E9F3BAC698F8"; //Mailer.mails = mail; //Mailer.Endpoint = "http://10.57.31.52:9002/"; //Mailer.RunAsync(); //Console.ReadLine(); MailerService.MailerService mailer = new MailerService.MailerService(); MailerService.Mails mail = new Mails(); MailerService.MailResponse mailResp = new MailResponse(); string[] recipients = new string[] { "*****@*****.**" }; mail.ApplicationGUID = "B02A6A55E3BD491ABE29E9F3BAC698F8"; mail.Content = "test"; mail.From = "*****@*****.**"; mail.Subject = "test"; mail.To = recipients; mailResp = mailer.SendLater(mail, DateTime.Now.AddSeconds(6)); Console.WriteLine(mailResp.ErrorMessage); Console.Read(); }
/// <inheritdoc /> /// <summary> /// Handles the specified transaction made message. /// </summary> /// <param name="paymentMadeMessage">The payment made message.</param> public void Handle(TransactionMadeMessage paymentMadeMessage) { string transactionId = paymentMadeMessage.Transaction.Id; string message = "TransactionMadeMessage " + "TransactionId=" + transactionId + " "; loggingService.Info(GetType(), message); CustomerModel customerModel = customerProvider.GetCustomerModel(paymentMadeMessage.UmbracoContext); TransactionModel model = paymentTranslator.Translate(paymentMadeMessage); model.CustomerId = customerModel.Id; databaseProvider.InsertTransaction(model); ///// do we want to send a confirmation email?? if (string.IsNullOrEmpty(paymentMadeMessage.EmailTemplateName) == false && string.IsNullOrEmpty(paymentMadeMessage.PaymentViewModel.EmailAddress) == false) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "PaymentId", transactionId }, { "AppointmentId", paymentMadeMessage.PaymentViewModel.AppointmentId }, { "PaymentAmount", paymentMadeMessage.PaymentViewModel.Amount.ToString(CultureInfo.InvariantCulture) }, }; loggingService.Info(GetType(), "Sending Email"); MailResponse mailResponse = mailProvider.SendEmail( paymentMadeMessage.UmbracoContext, paymentMadeMessage.EmailTemplateName, paymentMadeMessage.PaymentViewModel.EmailAddress, null, dictionary); //// TODO : we need to log the mail response! } }
/// <inheritdoc /> /// <summary> /// Sends the email. /// </summary> /// <param name="to">To.</param> /// <param name="model">The model.</param> /// <returns></returns> public MailResponse SendEmail( string to, MailTemplateModel model) { string mailTo = model.To; if (string.IsNullOrEmpty(mailTo)) { mailTo = to; } MailResponse response = new MailResponse { Contents = model.TokenizedText, Sent = true, ToEmailAddress = mailTo }; if (model.SurpressSendEmail == false) { MailMessage mailMessage = new MailMessage { From = new MailAddress(model.From), Subject = model.Subject, Body = model.TokenizedText, IsBodyHtml = model.IsHtml }; string[] emailto = mailTo.Split(';'); foreach (string mail in emailto) { if (mail != string.Empty) { mailMessage.To.Add(mail); } } if (string.IsNullOrEmpty(model.BlindCopy) == false) { string[] emailBcc = model.BlindCopy.Split(';'); foreach (string mail in emailBcc) { if (mail != string.Empty) { mailMessage.Bcc.Add(mail); } } } if (model.Attachments != null) { foreach (Attachment attachment in model.Attachments) { mailMessage.Attachments.Add(attachment); } } SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); } return(response); }
public object mail(Mail objMail) { try { //check for email existence in database bool EmailAlreadyExists = db.User_Registration.Any(x => x.Email_ID == objMail.Email_ID); if (ModelState.IsValid && EmailAlreadyExists == true) { //From : email ID string from = "*****@*****.**"; using (MailMessage mail = new MailMessage(from, objMail.Email_ID)) { //encode the encrypted email id var url = "http://localhost:4200/ForgetPwd/?token=" + HttpUtility.UrlEncode(Encryptword(objMail.Email_ID)); //adding elements to database forget_pwd.Email_id = objMail.Email_ID; forget_pwd.encryted_link = url; db.forgot_password.Add(forget_pwd); db.SaveChanges(); //set content for email mail.Subject = "Reset Password Link"; mail.Body = "Hello!\nWe received a request to reset the password for your account.\nIf you made this request, click the link given below. If you didn't make this request, you can ignore this email.\n" + url; mail.IsBodyHtml = false; //send email by simple mail transfer protocol SmtpClient smtp = new SmtpClient(); //set the ip address of the host smtp.Host = "smtp.gmail.com"; //specify the uses of SSL by SMTP smtp.EnableSsl = true; //credentials for authentication NetworkCredential networkCredential = new NetworkCredential(from, "raidinsurane1234"); smtp.UseDefaultCredentials = true; smtp.Credentials = networkCredential; //set the port for transactions and send email smtp.Port = 587; smtp.Send(mail); var res = "Successfull"; return(res); } } else { var res = new MailResponse(); res.message = "Invalid"; return(res); } } //catches an exception catch (Exception e) { HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request"); return(response); } }
public void SendMail(IEnumerable <CustomerModels> customers, EmailTemplate template, CancellationToken token) { MailResponse mailResponse = new MailResponse(); mailResponse.successMailCount = 0; mailResponse.totalCustomer = customers.Count(); mailResponse.status = "In Progress"; mailResponse.logs = new List <string>(); mailResponse.logs.Add("Started at : " + DateTime.Now.ToString("dd MMM, yyyy hh:mm tt")); int i = 1; //frist save SaveToJson(mailResponse); foreach (var customer in customers) { try { token.ThrowIfCancellationRequested(); SmtpClient smtpClient = MailSetup(); MailMessage mail = new MailMessage(); //Setting From , To and CC // mail.From = new MailAddress("*****@*****.**", "YarshaTech LMS"); mail.From = new MailAddress("*****@*****.**", "XYZA"); mail.To.Add(new MailAddress(customer.Email)); // mail.CC.Add(new MailAddress("*****@*****.**")); mail.IsBodyHtml = true; mail.Body = template.Message; mail.Subject = template.Subject; smtpClient.Send(mail); //save at each mail send mailResponse.successMailCount++; mailResponse.percentComplete = i / mailResponse.totalCustomer * 100; i++; mailResponse.logs.Add("Send mail to : " + customer.Email + " at :" + DateTime.Now.ToString("dd MMM, yyyy hh:mm tt")); SaveToJson(mailResponse); smtpClient.Dispose(); Thread.Sleep(10000); } catch (OperationCanceledException) { mailResponse.status = "Cancelled"; isMailServiceRunning = false; //Last save SaveToJson(mailResponse); cts.Cancel(); cts.Dispose(); cts = null; } catch (Exception ex) { failedSendMailList.Add(customer.Email); Console.Write(ex.Message); mailResponse.logs.Add("<span class='text-danger'>Error: Send mail to : " + customer.Email + " at :" + DateTime.Now.ToString("dd MMM, yyyy hh:mm tt") + "</span>"); //Last save SaveToJson(mailResponse); } } //save at last mailResponse.status = "Completed"; mailResponse.logs.Add("Completed at :" + DateTime.Now.ToString("dd MMM, yyyy hh:mm tt")); mailResponse.logs.Add("Total mail send " + mailResponse.successMailCount + " out of " + mailResponse.totalCustomer); SaveToJson(mailResponse); isMailServiceRunning = false; }