Exemple #1
0
        public async Task <IActionResult> Post([FromBody] EmailInput emailInput)
        {
            if (!ModelState.IsValid)
            {
                return((IActionResult)BadRequest(ModelState));
            }

            var subjectWithLocalTime = $"{emailInput.Subject} - {DateTime.Now.ToLocalTime().ToString()}";
            var attachment           = GetAttachmentFromMessage(emailInput.Body);

            _email.To(emailInput.ToAddresses)
            .Subject(subjectWithLocalTime)
            .Body(emailInput.Body)
            .Attach(attachment);
            if (!string.IsNullOrEmpty(emailInput.CcAddresses))
            {
                _email.CC(emailInput.CcAddresses);
            }
            if (!string.IsNullOrEmpty(emailInput.BccAddresses))
            {
                _email.BCC(emailInput.BccAddresses);
            }

            var response = await _sender.SendAsync(_email);

            return(response.Successful ? Ok() : (IActionResult)BadRequest(response));
        }