public HttpResponseMessage CreateGmailEmail([FromBody] GmailEmaillDto gmailEmaillDto) { try { Setup(); _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Info); var toEmailsList = new MailAddressCollection(); foreach (var email in gmailEmaillDto.ToEmail.Split(new [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)) { toEmailsList.Add(new MailAddress(email)); } Emailer.SendGmailSupportMessage(toEmailsList, gmailEmaillDto.Subject, gmailEmaillDto.Body); _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in WebAPI. Response {0}", HttpStatusCode.Created), LogLevelType.Info); return(this.Request.CreateResponse(HttpStatusCode.Created)); } catch (Exception ex) { _logger.WriteLogEntry(_tenantId.ToString(), new List <object> { ex.GetInnerMostExceptionWithEntityValidationInfo(), gmailEmaillDto.SerializeObjectToJsonString() }, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Error, ex); throw; } }
[Ignore] //This will actually send an email so have it setup to be ran manually. public void CreateGmailEmail() { //*** Arrange *** var mail = new GmailEmaillDto { ToEmail = "*****@*****.**", Subject = "SRTC error", Body = "skskksssssssssssss" }; var json = mail.SerializeObjectToJsonString(); //*** Act *** HttpResponseMessage response = _client.PostAsync("email/gmail/", new StringContent(json, Encoding.UTF8, "application/json")).Result; var reasonPhrase = response.ReasonPhrase; var myResponse = response.Content.ReadAsStringAsync(); var result = myResponse.Result; //*** Assert *** Assert.IsNotNull(json); }