public HttpResponseMessage SendTestEmail(SendTestEmailRequest request)
        {
            try
            {
                var mailFrom = request.SmtpServerMode == "h" ? Host.HostEmail : this.PortalSettings.Email;
                var mailTo   = this.UserInfo.Email;

                var errMessage = Mail.SendMail(mailFrom,
                                               mailTo,
                                               "",
                                               "",
                                               MailPriority.Normal,
                                               Localization.GetSystemMessage(this.PortalSettings, "EMAIL_SMTP_TEST_SUBJECT"),
                                               MailFormat.Text,
                                               Encoding.UTF8,
                                               "",
                                               "",
                                               request.SmtpServer,
                                               request.SmtpAuthentication.ToString(),
                                               request.SmtpUsername,
                                               request.SmtpPassword,
                                               request.EnableSmtpSsl);

                var success = string.IsNullOrEmpty(errMessage);
                return(this.Request.CreateResponse(success ? HttpStatusCode.OK : HttpStatusCode.BadRequest, new
                {
                    success,
                    errMessage,
                    confirmationMessage =
                        success
                            ? string.Format(
                            Localization.GetString(
                                "EmailSentMessage",
                                Components.Constants.ServersResourcersPath),
                            mailFrom,
                            mailTo)
                            : Localization.GetString("errorMessageSendingTestEmail"),
                }));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage SendTestEmail(SendTestEmailRequest request)
        {
            try
            {
                var smtpHostMode = request.SmtpServerMode == "h";
                var mailFrom     = smtpHostMode ? Host.HostEmail : this.PortalSettings.Email;
                var mailTo       = this.UserInfo.Email;

                var errMessage = Mail.SendMail(mailFrom,
                                               mailTo,
                                               "",
                                               "",
                                               MailPriority.Normal,
                                               Localization.GetSystemMessage(this.PortalSettings, "EMAIL_SMTP_TEST_SUBJECT"),
                                               MailFormat.Text,
                                               Encoding.UTF8,
                                               "",
                                               "",
                                               smtpHostMode ? HostController.Instance.GetString("SMTPServer") : request.SmtpServer,
                                               smtpHostMode ? HostController.Instance.GetString("SMTPAuthentication") : request.SmtpAuthentication.ToString(),
                                               smtpHostMode ? HostController.Instance.GetString("SMTPUsername") : request.SmtpUsername,
                                               smtpHostMode ? HostController.Instance.GetEncryptedString("SMTPPassword", Config.GetDecryptionkey()) : request.SmtpPassword,
                                               smtpHostMode ? HostController.Instance.GetBoolean("SMTPEnableSSL", false) : request.EnableSmtpSsl);

                var success = string.IsNullOrEmpty(errMessage);
                return(this.Request.CreateResponse(success ? HttpStatusCode.OK : HttpStatusCode.BadRequest, new
                {
                    success,
                    errMessage,
                    confirmationMessage =
                        string.Format(
                            Localization.GetString(
                                "EmailSentMessage",
                                Components.Constants.ServersResourcersPath),
                            mailFrom,
                            mailTo),
                }));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Exemplo n.º 3
0
        //public async Task<HttpResponseMessage> GetSendEmail([FromUri]SendTestEmailRequest request)
        public HttpResponseMessage GetSendEmail([FromUri] SendTestEmailRequest request)
        {
            HttpResponseMessage httpResponse = null;
            string       uri      = string.Empty;
            IResultModel response = new ResultModel();

            try
            {
                response = this.mainService.SendTestEmail(request.email, request.message);
            }
            catch (Exception ex)
            {
                response.OnException(ex);
            }

            uri = Url.Link("AlfredSendEmailApi", new { id = 0 });

            httpResponse = Request.CreateResponse <IResultModel>(HttpStatusCode.Created, response);
            httpResponse.Headers.Location = new Uri(uri);

            return(httpResponse);
        }