コード例 #1
0
ファイル: Email.cs プロジェクト: jose-sanchez/Camiher
        /// <summary>
        /// Send a email
        /// </summary>
        /// <param name="fromAddress"></param>
        /// <param name="toAddress"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="imagePath"></param>
        /// <returns></returns>
        public Boolean SendEmail(MailAddress fromAddress, MailAddress toAddress, string subject, string body, String[] imagePath)
        {
            Boolean emailSent = true;

            //Create the email
            var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body    = body
            };

            foreach (string path in imagePath)
            {
                var attachment = new Attachment(path);
                message.Attachments.Add(attachment);
            }
            try
            {
                _smtpClient.Send(message);
            }
            catch (Exception ex)
            {
                emailSent = false;
                AppLogger.ErrorException(String.Format("Unable to send email from {0} to {1}",
                                                       fromAddress.Address, toAddress.Address), ex);
            }

            return(emailSent);
        }