Example #1
0
        public static bool SentEmail(string pMessage, bool wToTheClientFlag, ChatMailSenderBE pChatMailSender, ChatUserBE pChatUser)
        {
            try
            {
                if (pChatMailSender == null || pChatUser == null)
                {
                    return(false);
                }

                System.Net.Mail.MailMessage wMessage = new System.Net.Mail.MailMessage();

                SmtpClient wSmtpClient = new SmtpClient(pChatMailSender.SMTPServer, pChatMailSender.SMTPPort);

                //Configuraciones de la cuenta
                wSmtpClient.UseDefaultCredentials = false;
                wSmtpClient.Credentials           = new System.Net.NetworkCredential(pChatMailSender.UserName, pChatMailSender.Password);

                wSmtpClient.Timeout   = 300000;
                wSmtpClient.EnableSsl = pChatMailSender.EnableSSL;
                //wSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;


                //Configuraciones del email
                wMessage = new System.Net.Mail.MailMessage()
                {
                    Body = pMessage, BodyEncoding = Encoding.UTF8, IsBodyHtml = true
                };


                //Configuro el FROM y TO .
                wMessage.From = new MailAddress(pChatMailSender.Email);

                string wSubject = string.Empty;
                if (wToTheClientFlag)
                {
                    wMessage.To.Add(new MailAddress(pChatUser.ChatUserEmail)); //En el caso de que sea desde la empresa para el cliente
                    wMessage.Subject = "- [Chat Epiron] - ";                   //<--- completar
                }
                else
                {
                    wMessage.To.Add(new MailAddress(pChatMailSender.Email));//En el caso de que sea desde el cliente para la empresa
                    //El asunto o subject del email para el caso wToTheClientFlag == false, se conforma con el formtamo [TAG]@Email_del_cliente[/TAG]
                    wMessage.Subject = pChatMailSender.TagStartWith + pChatUser.ChatUserEmail + pChatMailSender.TagEndWith;
                }

                System.Net.Mail.Attachment wAttachFile = null; //<--- por ahora sin attachments

                wSmtpClient.Send(wMessage);
            }
            catch (Exception ex)
            {
            }
            return(true);
        }
Example #2
0
        public static bool SentEmail(string pMessage, bool wToTheClientFlag, ChatMailSenderBE pChatMailSender, ChatUserBE pChatUser)
        {
            try
            {
                if (pChatMailSender == null || pChatUser == null)
                    return false;

                System.Net.Mail.MailMessage wMessage = new System.Net.Mail.MailMessage() ;

                SmtpClient wSmtpClient = new SmtpClient(pChatMailSender.SMTPServer, pChatMailSender.SMTPPort);

                //Configuraciones de la cuenta 
                wSmtpClient.UseDefaultCredentials = false;
                wSmtpClient.Credentials = new System.Net.NetworkCredential(pChatMailSender.UserName, pChatMailSender.Password);
                
                wSmtpClient.Timeout = 300000;
                wSmtpClient.EnableSsl = pChatMailSender.EnableSSL;
                //wSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                
              
                //Configuraciones del email 
                wMessage = new System.Net.Mail.MailMessage() { Body = pMessage,BodyEncoding = Encoding.UTF8, IsBodyHtml = true };


                //Configuro el FROM y TO . 
                wMessage.From = new MailAddress(pChatMailSender.Email);

                string wSubject = string.Empty;
                if (wToTheClientFlag)
                {
                    wMessage.To.Add(new MailAddress(pChatUser.ChatUserEmail));  //En el caso de que sea desde la empresa para el cliente
                    wMessage.Subject = "- [Chat Epiron] - "; //<--- completar
                }
                else
                {
                    wMessage.To.Add(new MailAddress(pChatMailSender.Email));//En el caso de que sea desde el cliente para la empresa 
                    //El asunto o subject del email para el caso wToTheClientFlag == false, se conforma con el formtamo [TAG]@Email_del_cliente[/TAG]
                    wMessage.Subject = pChatMailSender.TagStartWith + pChatUser.ChatUserEmail + pChatMailSender.TagEndWith;
                }

                System.Net.Mail.Attachment wAttachFile = null; //<--- por ahora sin attachments

                wSmtpClient.Send(wMessage);

            }
            catch (Exception ex)
            {

            }
            return true;
        
        }
        /// <summary>
        /// Trae los datos sobre la cuenta de email con que se deben mandar los correos
        /// </summary>
        /// <param name="pChatConfigGuid">id configuraciĆ³n de la cuenta</param>
        /// <returns></returns>
        public static ChatMailSenderBE GetChatMailSenderByCongGuid(Guid pChatConfigGuid)
        {
            ChatMailSenderBE wChatMailSender = null;
            Database database = null;
            int? recordId = null;
            //try
            //{
                database = DatabaseFactory.CreateDatabase("EpironChat_LogsConnectionString");
                using (DbCommand cmd = database.GetStoredProcCommand("[Chat].[ChatMailSender_s_ByChatConfigGuid]"))
                {
                    database.AddInParameter(cmd, "ChatConfigGuid", DbType.Guid, pChatConfigGuid);
                    using (IDataReader reader = database.ExecuteReader(cmd))
                    {
                        while (reader.Read())
                        {
                            wChatMailSender = new ChatMailSenderBE();

                            if (reader["Email"] != DBNull.Value)
                                wChatMailSender.Email = Convert.ToString(reader["Email"]);

                            if (reader["Password"] != DBNull.Value)
                                wChatMailSender.Password = Convert.ToString(reader["Password"]);

                            if (reader["UserName"] != DBNull.Value)
                                wChatMailSender.UserName = Convert.ToString(reader["UserName"]);

                            if (reader["SMTPServer"] != DBNull.Value)
                                wChatMailSender.SMTPServer = Convert.ToString(reader["SMTPServer"]);

                            if (reader["SMTPPort"] != DBNull.Value)
                                wChatMailSender.SMTPPort = Convert.ToInt32(reader["SMTPPort"]);

                            if (reader["EnableSSL"] != DBNull.Value)
                                wChatMailSender.EnableSSL = Convert.ToBoolean(reader["EnableSSL"]);

                            if (reader["TagStartWith"] != DBNull.Value)
                                wChatMailSender.TagStartWith = Convert.ToString(reader["TagStartWith"]);

                            if (reader["TagEndWith"] != DBNull.Value)
                                wChatMailSender.TagEndWith = Convert.ToString(reader["TagEndWith"]);
                        }
                    }
                }
                return wChatMailSender;
            //}
            //catch (Exception ex)
            //{
            //    throw SecPortalException.ProcessException(ex, typeof(EpironChatDAC), "EpironChatConnectionString");
            //}
        }
Example #4
0
        public ActionResult SendEmail(string cellPhone, string email, string emailBody, bool toTheClientFlag, string pGuid, int pRoomId, int pIsNoOperator)
        {
            try
            {
                ChatMailSenderBE wChatMailSenderBE = null;
                if (pGuid == "0")
                {
                    ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(null);
                    wChatMailSenderBE = EpironChatEmailBC.GetChatMailSenderByCongGuid(chatConfigBE.ChatConfigGuid);
                }
                else
                {
                    Guid wGuid = new Guid(pGuid);
                    wChatMailSenderBE = EpironChatEmailBC.GetChatMailSenderByCongGuid(wGuid);
                }

                ChatUserBE wChatUserBE = new ChatUserBE();
                wChatUserBE.ChatUserEmail = email; //<--usaremos el email que el usuario nos provee, aunque este tenga uno previo, no lo modificaremos en la base

                if (toTheClientFlag)
                {
                    string css = @"
<style>.bubbleOwn
    {
        position: relative;
        width: 60%;
        /*height: 35px;*/
        padding: 5px;
        background-color: #71C837;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        border-radius: 3px;
        left: 1px;
        clear: both;
       margin:6px 0px 1px 8px;
        border: 1px solid #CCC;
        /*min-height: 35px;*/
    }

    .bubbleThey
    {
        position: relative;
        width: 60%;
        /*height: 35px;*/
        padding: 2px;
        background: white;
        border: 1px solid #CCC;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        border-radius: 3px;
        float: right;
        margin-right: 1px;
        clear: both;
        margin:6px 8px 1px 0px;
        /*min-height: 35px;*/
    }

._time {
float: right;
font-size: 10px;
}
</style>";
                    emailBody = css + emailBody;
                }



                bool isSent = EmailHelper.SentEmail(emailBody, toTheClientFlag, wChatMailSenderBE, wChatUserBE);

                if (isSent)
                {
                    //se registra en la base que se ha enviado un email
                    ChatEmailMessageBE wChatEmailMessageBE = new ChatEmailMessageBE();
                    // pIsNoOperator <-- Indica si este email se envia tras no encontrar operadores disponibles
                    wChatEmailMessageBE.ChatDescription = pIsNoOperator == 1 ? "SIN-OPERADORES" : null;
                    wChatEmailMessageBE.EmailFrom       = wChatMailSenderBE.Email;
                    if (pRoomId != 0)
                    {
                        wChatEmailMessageBE.ChatRoomId = pRoomId;
                    }
                    else
                    {
                        wChatEmailMessageBE.ChatRoomId = null;
                    }

                    wChatEmailMessageBE.Body = emailBody;
                    if (toTheClientFlag)
                    {
                        wChatEmailMessageBE.Subject     = "-Subject-";
                        wChatEmailMessageBE.DeliveredTo = wChatUserBE.ChatUserEmail;
                    }
                    else
                    {
                        wChatEmailMessageBE.Subject     = wChatMailSenderBE.TagStartWith + wChatUserBE.ChatUserEmail + wChatMailSenderBE.TagEndWith;
                        wChatEmailMessageBE.DeliveredTo = wChatMailSenderBE.Email;
                    }


                    bool saved = EpironChatEmailBC.InsertChatEmailMessage(wChatEmailMessageBE);

                    if (saved)
                    {
                        return(Json(new { Result = "OK", Message = "Correo enviado correctamente" }));
                    }
                    else
                    {
                        return(Json(new { Result = "OK", Message = "Error al Guardar el Email" })); //<-- Revisar si se debe o no avisar al cliente
                    }
                }
                else
                {
                    return(Json(new { Result = "OK", Message = "Error al Enviar Correo" })); //<-- Revisar si se debe o no avisar al cliente
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex) }));
            }
        }
        /// <summary>
        /// Trae los datos sobre la cuenta de email con que se deben mandar los correos
        /// </summary>
        /// <param name="pChatConfigGuid">id configuraciĆ³n de la cuenta</param>
        /// <returns></returns>
        public static ChatMailSenderBE GetChatMailSenderByCongGuid(Guid pChatConfigGuid)
        {
            ChatMailSenderBE wChatMailSender = null;
            Database         database        = null;
            int?recordId = null;

            //try
            //{
            database = DatabaseFactory.CreateDatabase("EpironChat_LogsConnectionString");
            using (DbCommand cmd = database.GetStoredProcCommand("[Chat].[ChatMailSender_s_ByChatConfigGuid]"))
            {
                database.AddInParameter(cmd, "ChatConfigGuid", DbType.Guid, pChatConfigGuid);
                using (IDataReader reader = database.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        wChatMailSender = new ChatMailSenderBE();

                        if (reader["Email"] != DBNull.Value)
                        {
                            wChatMailSender.Email = Convert.ToString(reader["Email"]);
                        }

                        if (reader["Password"] != DBNull.Value)
                        {
                            wChatMailSender.Password = Convert.ToString(reader["Password"]);
                        }

                        if (reader["UserName"] != DBNull.Value)
                        {
                            wChatMailSender.UserName = Convert.ToString(reader["UserName"]);
                        }

                        if (reader["SMTPServer"] != DBNull.Value)
                        {
                            wChatMailSender.SMTPServer = Convert.ToString(reader["SMTPServer"]);
                        }

                        if (reader["SMTPPort"] != DBNull.Value)
                        {
                            wChatMailSender.SMTPPort = Convert.ToInt32(reader["SMTPPort"]);
                        }

                        if (reader["EnableSSL"] != DBNull.Value)
                        {
                            wChatMailSender.EnableSSL = Convert.ToBoolean(reader["EnableSSL"]);
                        }

                        if (reader["TagStartWith"] != DBNull.Value)
                        {
                            wChatMailSender.TagStartWith = Convert.ToString(reader["TagStartWith"]);
                        }

                        if (reader["TagEndWith"] != DBNull.Value)
                        {
                            wChatMailSender.TagEndWith = Convert.ToString(reader["TagEndWith"]);
                        }
                    }
                }
            }
            return(wChatMailSender);
            //}
            //catch (Exception ex)
            //{
            //    throw SecPortalException.ProcessException(ex, typeof(EpironChatDAC), "EpironChatConnectionString");
            //}
        }