コード例 #1
0
ファイル: Email.cs プロジェクト: jcme64/TesteDevEspp
        public string Send()
        {
            string retorno = string.Empty;

            Message.BodyEncoding = UTF8Encoding.UTF8;
            Message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            Message.From = new System.Net.Mail.MailAddress(FromAddress);

            FileAttached.ToList().ForEach(x => Message.Attachments.Add(new System.Net.Mail.Attachment(x)));

            ToAddress.ToList().ForEach(x => Message.To.Add(new System.Net.Mail.MailAddress(x)));

            ToAddressCopy.ToList().ForEach(x => Message.CC.Add(new System.Net.Mail.MailAddress(x)));

            Message.Subject            = Subject;
            Message.Body               = Body;
            Smtp.UseDefaultCredentials = false;
            Smtp.Timeout               = 180000;
            Smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;

            Smtp.Credentials = new System.Net.NetworkCredential(Acount, PassWord);

            try
            {
                Smtp.Send(Message);
                retorno = "";
            }
            catch (Exception ex_)
            {
                retorno = ex_.InnerException != null ? (ex_.InnerException).Message : ex_.Message;
            }

            return(retorno);
        }