Пример #1
0
        private static string PrepareMailAddress(string address)
        {
            if (!string.IsNullOrEmpty(address))
            {
                return(MailMessageBuilder.ParseRecipients(address).ToString().Replace(",", ";"));
            }

            return(string.Empty);
        }
Пример #2
0
        public static SmtpElement SendMail(string from, string toRecipients, string ccRecipients, string bccRecipients, string subject, string body, bool isHighPriority, List <Attachment> attachments)
        {
            SmtpElement smtpElement;

            if (!String.IsNullOrEmpty(from))
            {
                from = Nhea.Text.StringHelper.ReplaceTurkishCharacters(from.ToLower().Trim());

                smtpElement = Nhea.Configuration.Settings.Communication.SmtpSettings.Where(smtpElementQuery => smtpElementQuery.From == from).First();
            }
            else
            {
                smtpElement = Nhea.Configuration.Settings.Communication.SmtpSettings.Where(smtpElementQuery => smtpElementQuery.IsDefault == true).First();
            }

            if (smtpElement != null)
            {
                MailMessage mailMessage = MailMessageBuilder.Build(smtpElement, toRecipients, ccRecipients, bccRecipients, subject, body, isHighPriority, attachments);

                SmtpClient smtpClient = SmtpClientBuilder.Build(smtpElement);
                smtpClient.Send(mailMessage);

                return(smtpElement);
            }
            else
            {
                if (!String.IsNullOrEmpty(from))
                {
                    throw new Exception("Related smtp setting could not found! From: " + from);
                }
                else
                {
                    throw new Exception("Default smtp setting could not found!");
                }
            }
        }