Exemple #1
0
        /// <summary>
        ///     Sends mail message.
        /// </summary>
        /// <param name="former"></param>
        /// <param name="mail"></param>
        public static void SendMail(this FromerInfo former, MailInfo mail)
        {
            try
            {
                var msg = new MailMessage
                {
                    From            = new MailAddress(former.FromAddress, former.DisplayName, Encoding.UTF8),
                    Subject         = mail.Subject,
                    SubjectEncoding = Encoding.UTF8,
                    Body            = mail.Body,
                    BodyEncoding    = Encoding.UTF8,
                    IsBodyHtml      = mail.IsHtml,
                    Priority        = MailPriority.Normal
                };

                if (mail.Address.IndexOf(',') > -1)
                {
                    var mailAddresses = mail.Address.Split(',');

                    foreach (var item in mailAddresses)
                    {
                        if (item.Trim() != string.Empty)
                        {
                            msg.To.Add(item);
                        }
                    }
                }

                else
                {
                    msg.To.Add(mail.Address);
                }

                var client = new SmtpClient(former.Host, former.Port)
                {
                    EnableSsl   = true,
                    Credentials = new NetworkCredential(former.FromAddress, former.Password)
                };

                client.Send(msg);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        ///     Sends mail message.
        /// </summary>
        /// <param name="former"></param>
        /// <param name="mail"></param>
        public static void SendMail(this FromerInfo former, MailInfo mail)
        {
            var msg = new MailMessage
            {
                From = new MailAddress(former.FromAddress, former.DisplayName, Encoding.UTF8),

                Subject = mail.Subject,

                SubjectEncoding = Encoding.UTF8,

                Body = mail.Body,

                BodyEncoding = Encoding.UTF8,

                IsBodyHtml = mail.IsHtml,

                Priority = MailPriority.Normal
            };

            if (mail.Address.IndexOf(',') > -1)
            {
                var addresses = mail.Address.Split(',').Where(w => !string.IsNullOrWhiteSpace(w.Trim()));

                foreach (var address in addresses)
                {
                    msg.To.Add(address);
                }
            }

            else
            {
                msg.To.Add(mail.Address);
            }

            var client = new SmtpClient(former.Host, former.Port)
            {
                EnableSsl = true,

                Credentials = new NetworkCredential(former.FromAddress, former.Password)
            };

            client.Send(msg);
        }