public void SendMail(OutgoingMailModel mailModel) { // Send mail to recipient var attachments = new Dictionary <string, byte[]>(); if (mailModel.attachments != null) { foreach (var mediaId in mailModel.attachments) { var mediaItem = _mediaItemManager.GetOne(mediaId); if (mediaItem != null) { byte[] data = new byte[mediaItem.Data.Length]; mediaItem.Data.Read(data, 0, data.Length); attachments.Add(mediaItem.Name, data); } else { throw new Exception("Failed to fetch media item for id " + mediaId + "."); } // Dispose stream that is no longer needed. Handle this in some better way? mediaItem.Data.Dispose(); } } string body = mailModel.message; _exchangeMailWebApi.ConnectToExchangeService(ConfigurationManager.AppSettings["chalmersIllExhangeLogin"], ConfigurationManager.AppSettings["chalmersIllExhangePass"]); _exchangeMailWebApi.SendMailMessage(mailModel.OrderId, body, ConfigurationManager.AppSettings["chalmersILLMailSubject"], mailModel.recipientName, mailModel.recipientEmail, attachments); }
public DelayedMailOperation(int internalOrderId, OutgoingMailModel mail) { this.InternalOrderId = internalOrderId; this.Mail = mail; LogMessages = new List <LogMessage>(); ShouldBeProcessed = false; }
public string GetDestinations(string reference, long id) { var log = new SysLogModel(); var json = new OutgoingMailModel(reference, id).GetDestinations(); log.Finish(json.Length); return(json); }
public async Task <IActionResult> Post([FromBody] AppDetails appDetails) { if (appDetails.ToAddress == null) { return(BadRequest(new APIResponse { CorelationID = _corelationGuid.ToString(), Status = "To Address is empty", StatusCode = HttpStatusCode.OK })); } if (appDetails.ToAddress.Count == 0) { return(BadRequest(new APIResponse { CorelationID = _corelationGuid.ToString(), Status = "To Address is empty", StatusCode = HttpStatusCode.OK })); } OutgoingMailModel mailModel = new OutgoingMailModel { FromAddress = _mailerSettings.FromAddress, ToAddress = appDetails.ToAddress, Subject = $"{appDetails.AlertType} in application {appDetails.AppName} with app id {appDetails.AppID}", Body = appDetails.Message }; HttpClient httpClient = new HttpClient(); HttpResponseMessage response = null; try { StringContent mailContent = new StringContent(JsonConvert.SerializeObject(mailModel), Encoding.UTF8, "application/json"); response = await httpClient.PostAsync(_mailerSettings.MailServiceUrl, mailContent); response.EnsureSuccessStatusCode(); return(Ok(new APIResponse { CorelationID = _corelationGuid.ToString(), Status = "Mail sent sucessfully", StatusCode = HttpStatusCode.OK })); } catch (Exception ex) { Console.Write($"error sending mail {ex.Message}"); HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Json(new APIResponse { CorelationID = _corelationGuid.ToString(), Status = $"Error while seding mail exception:-{ex.Message}", StatusCode = HttpStatusCode.InternalServerError, })); } }
public string GetDestinations(IContext context, string reference, long id) { var log = new SysLogModel(context: context); var json = new OutgoingMailModel( context: context, reference: reference, referenceId: id) .GetDestinations(context: context); log.Finish(context: context, responseSize: json.Length); return(json); }
public ActionResult SendSimpleMail(OutgoingMailModel m) { var res = new ResultResponse(); try { _mailService.SendMail(m); res.Success = true; res.Message = "Lyckades med att skicka ut mail."; } catch (Exception e) { res.Success = false; res.Message = "Misslyckades med att skicka ut mail: " + e.Message; } return(Json(res, JsonRequestBehavior.AllowGet)); }