Exemplo n.º 1
0
        public MailSettingsParameter(MailConfigurationModel model)
        {
            if (model == null)
            {
                return;
            }

            this.MailServer = model.MailServer;
            this.SenderMail = model.Sender;
            this.EnableSsl  = model.UseSsl;
            this.Password   = model.Password;
            this.Port       = model.Port;
            this.Username   = model.Username;
        }
        /// <summary>
        /// Send an e-mail notification
        /// </summary>
        /// <param name="subject">Subject of the notification</param>
        /// <param name="message">Message of the notification</param>
        /// <param name="isHTML">It indicates whether the content is html</param>
        /// <param name="receivers">Receivers of the notification</param>
        /// <param name="senderMask">Mask sender of the notification</param>
        /// <param name="pTransmitterMailConfiguration">Transmitter mail configuration</param>
        public int SendEmailSMTPDefined(string subject, string message, List <string> receivers, MailConfigurationModel pTransmitterMailConfiguration, bool isHTML = false, string senderMask = "")
        {
            try
            {
                string url = $"{ApiUrl}/notification/send-email";

                NotificationModel model = new NotificationModel()
                {
                    subject = subject, message = message, receivers = receivers, is_html = isHTML, sender_mask = senderMask, community_short_name = CommunityShortName, transmitter_mail_configuration = pTransmitterMailConfiguration
                };
                string result = WebRequestPostWithJsonObject(url, model);
                int    mailID = Int32.Parse(result);

                Log.Debug($"Email {subject} sended to {string.Join(",", receivers)}");
                return(mailID);
            }
            catch (Exception ex)
            {
                Log.Error($"Error sending mail {subject} to {string.Join(",", receivers)}: \r\n{ex.Message}");
                throw;
            }
        }