Esempio n. 1
0
        private void SendMail(EMessageAction action, EMessageStyle style, string name, DateTime date)
        {
            PlainTextMessage mess    = new PlainTextMessage(action, style, name, date);
            HTMLMessage      htmmess = new HTMLMessage(action, style, name, date);

            MailMessage mailMessage = new MailMessage();

            // Direciones
            mailMessage.From = new MailAddress(_source);
            mailMessage.To.Add(_destination);

            // Asunto
            mailMessage.Subject = mess.Subject;
            // Cuerpo en texto plano
            mailMessage.Body = mess.Body;

            // Add HTML View
            AlternateView altHtml = AlternateView.CreateAlternateViewFromString(htmmess.Body, null, "text/html");

            mailMessage.AlternateViews.Add(altHtml);

            try
            {
                EnviaEmail(mailMessage);
            }

            catch (Exception ex)
            {
                Builder.Output(string.Format("{0}.SendMail: Ocurrió una excepción: {1}", ClassName, ex.Message), TraceEventType.Error);
                throw ex;
            }
        }
Esempio n. 2
0
        private void SendMail(EMessageAction action, EMessageStyle style, ClientData client, DateTime date)
        {
            PlainTextMessage mess    = new PlainTextMessage(action, style, client.Name, date);
            HTMLMessage      htmmess = new HTMLMessage(action, style, client.Name, date);

            MailMessage mailMessage = new MailMessage();

            // Direciones
            mailMessage.From = new MailAddress(_source);
            mailMessage.To.Add(_destination);

            // Asunto
            mailMessage.Subject = mess.Subject;
            // Cuerpo en texto plano
            mailMessage.Body = mess.Body;

            // Add HTML View
            AlternateView altHtml = AlternateView.CreateAlternateViewFromString(htmmess.Body, null, "text/html");

            mailMessage.AlternateViews.Add(altHtml);

            // Incorporar adjunto si esta configurado en el cliente
            // y es una accion Timeout o Dead
            bool UseAttach = client.LogAttachEnabled && (action == EMessageAction.Timeout) || (action == EMessageAction.Dead);

            FileStream fs = null;

            if (UseAttach && File.Exists(client.LogFilePath))
            {
                fs = new FileStream(client.LogFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                mailMessage.Attachments.Add(new Attachment(fs, "Archivo Log", "text/plain"));
            }

            try
            {
                EnviaEmail(mailMessage);
            }

            catch (Exception ex)
            {
                Builder.Output(string.Format("{0}.SendMail: Ocurrió una excepción: {1}", ClassName, ex.Message), TraceEventType.Error);
                throw ex;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }