public void SendEmailAsync(string EmailAddress, string subject, string body)
 {
     var msg = PrepareMessage(EmailAddress, subject, body);
     SendEmailDelegate sd = new SendEmailDelegate(_smtpClient.Send);
     AsyncCallback cb = new AsyncCallback(SendEmailResponse);
     sd.BeginInvoke(msg, cb, sd); 
 }        
Example #2
0
        public static void SendEmail(System.Net.Mail.MailMessage m, TipoCorreo tipo)
        {
            string NetWorkEmail    = System.Configuration.ConfigurationManager.AppSettings["NetEmail"];
            string NetWorkPassword = System.Configuration.ConfigurationManager.AppSettings["NetPassword"];

            if (tipo == TipoCorreo.ReseteoDeClave)
            {
                m.From = new MailAddress(NetWorkEmail, "Nueva clave " + AboutInfo.Instance.ProductName);
            }
            else if (tipo == TipoCorreo.Informativo)
            {
                m.From = new MailAddress(NetWorkEmail, "Informativo " + AboutInfo.Instance.ProductName);
            }

            SmtpClient smtp = new SmtpClient();

            smtp.Host                  = System.Configuration.ConfigurationManager.AppSettings["NetHost"];
            smtp.Port                  = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["NetPort"]);
            smtp.EnableSsl             = false;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new NetworkCredential(NetWorkEmail, NetWorkPassword);

            SendEmailDelegate sd = new SendEmailDelegate(smtp.Send);
            AsyncCallback     cb = new AsyncCallback(SendEmailResponse);

            sd.BeginInvoke(m, cb, sd);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Notifications"/> class.
 /// </summary>
 public Notifications()
 {
     this.sendEmailDelegate    = new SendEmailDelegate(this.SendEmail);
     this.sendSmsDelegate      = new SendSmsDelegate(this.SendSms);
     this.initiateCallDelegate = new InitiateCallDelegate(this.InitiateCall);
     this.sendToMshDelegate    = new SendToMshDelegate(this.SendToMsh);
 }
Example #4
0
        public void SendEmailAsync(string emailId, string subject, string body)
        {
            var msg = PrepareMessage(emailId, subject, body);
            SendEmailDelegate sd = new SendEmailDelegate(_smtpClient.Send);
            AsyncCallback     cb = new AsyncCallback(SendEmailResponse);

            sd.BeginInvoke(msg, cb, sd);
        }
        /// <summary>
        /// This function is used to send mail and invoking threads
        /// </summary>
        /// <param name="name"></param>
        /// <param name="emailAddress"></param>
        /// <returns></returns>
        public string SendEmailAsync(string name, string emailAddress)
        {
            SendEmailDelegate dc = new SendEmailDelegate(this.SendEmail);
            AsyncCallback     cb = new AsyncCallback(this.GetResultsOnCallback);
            IAsyncResult      ar = dc.BeginInvoke(name, emailAddress, cb, null);

            return("ok");
        }
Example #6
0
        private void SendEmailResponse(IAsyncResult ar)
        {
            SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);

            try
            {
                sd.EndInvoke(ar);
            }
            catch (Exception ex)
            {
            }
        }
 private static void SendEmailResponse(IAsyncResult ar)
 {
     try
     {
         SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);
         sd.EndInvoke(ar);
     }
     catch (Exception ex)
     {
         new LogManager(typeof(string)).LogError(ex.Message, ex);
         throw;
     }
 }
Example #8
0
        public void GetResultsOnCallback(IAsyncResult ar)
        {
            SendEmailDelegate del = (SendEmailDelegate)((AsyncResult)ar).AsyncDelegate;

            try
            {
                bool result = del.EndInvoke(ar);
            }
            catch (Exception ex)
            {
                bool result = false;
            }
        }
Example #9
0
        private static void SendEmailResponse(IAsyncResult ar)
        {
            try
            {
                SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);

                sd.EndInvoke(ar);
            }
            catch (Exception ex)
            {
                Exception Error = new Exception("Send Email Delegate" + ex.Message);
            }
        }
Example #10
0
 public string SendEmailAsync()
 {
     try
     {
         SendEmailDelegate dc = new SendEmailDelegate(this.SendEmail);
         AsyncCallback     cb = new AsyncCallback(this.GetResultsOnCallback);
         IAsyncResult      ar = dc.BeginInvoke(cb, null);
         return("ok");
     }
     catch
     {
         return("Not ok");
     }
 }
Example #11
0
        private void SendEmailResponse(IAsyncResult ar)
        {
            SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);

            try
            {
                sd.EndInvoke(ar);
                LOG("Successfully!");
            }
            catch (Exception ex)
            {
                LOG(ex.Message);
            }
        }
Example #12
0
 public bool SendEmailAsync(string sendTo, string msgBody, string msgSubject)
 {
     try
     {
         var          dc = new SendEmailDelegate(SendMail);
         var          cb = new AsyncCallback(this.GetResultsOnCallback);
         IAsyncResult ar = dc.BeginInvoke(sendTo, msgBody, msgSubject, cb, null);
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Example #13
0
 public bool SendEmailAsync(string toEmail, string toName)
 {
     try
     {
         SendEmailDelegate dc = new SendEmailDelegate(this.SendEmail);
         AsyncCallback     cb = new AsyncCallback(this.GetResultsOnCallback);
         IAsyncResult      ar = dc.BeginInvoke(toEmail, toName, cb, null);
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// function to get the result callback method
        /// </summary>
        /// <param name="ar"></param>
        public void GetResultsOnCallback(IAsyncResult ar)
        {
            SendEmailDelegate del = (SendEmailDelegate)
                                    ((AsyncResult)ar).AsyncDelegate;

            try
            {
                string result;
                result = del.EndInvoke(ar);
                Debug.WriteLine("\nOn CallBack: result is " + result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\nOn CallBack, problem occurred: " + ex.Message);
            }
        }
Example #15
0
        public static void SendEmail(MailMessage m, Boolean Async)
        {
            SmtpClient smtp = null;

            smtp = new SmtpClient();

            if (Async)
            {
                SendEmailDelegate sd = new SendEmailDelegate(smtp.Send);
                AsyncCallback     cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(m, cb, sd);
            }
            else
            {
                smtp.Send(m);
            }
        }
        /// <summary>
        /// Send a email message
        /// </summary>
        /// <param name="emailMessage"></param>
        /// <returns></returns>

        /*public bool Send(MailMessage emailMessage)
         * {
         *  try
         *  {
         *      //MailMessage mail = new MailMessage("emailfrom", "emailto");
         *      //mail.From = new MailAddress("emailfrom");
         *      //mail.Subject = txtsbjct.Text;
         *      //string Body = txtmsg.Text;
         *      //mail.Body = Body;
         *      //mail.IsBodyHtml = true;
         *
         *      smtp.Host = ConfigSettings.ReadConfigValue("SmtpHost", "mail.masholdings.com"); //Or Your SMTP Server Address
         *      smtp.Credentials = new System.Net.NetworkCredential(ConfigSettings.ReadConfigValue("SmtpClientUser", "IThelpDesk")
         *          , ConfigSettings.ReadConfigValue("SmtpClientPassword", "welcome@123"));
         *
         *      //smtp.EnableSsl = true;
         *      smtp.SendAsync(emailMessage, emailMessage);
         *      base.SendComplete(emailMessage);
         *      emailMessage = null;
         *      smtp = null;
         *      return true;
         *  }
         *  catch (System.Exception e)
         *  {
         *      this.LogError("Failed to send a email message to " + emailMessage.To.ToString(), e);
         *      return false;
         *  }
         * }
         *
         * void smtp_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
         * {
         *  try
         *  {
         *      this.LogInfo("Email Sent with Error: " + e.Error + " To: " + ((MailMessage)sender).To.ToString());
         *  }
         *  catch { }
         * }*/

        #region TestCode
        /// <summary>
        /// Send a email message
        /// </summary>
        /// <param name="emailMessage"></param>
        /// <returns></returns>
        public bool Send(System.Net.Mail.MailMessage m)
        {
            try
            {
                System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
                smtpClient.Host        = ConfigSettings.ReadConfigValue("SmtpHost", "mail.masholdings.com"); //Or Your SMTP Server Address
                smtpClient.Credentials = new System.Net.NetworkCredential(ConfigSettings.ReadConfigValue("SmtpClientUser", "IThelpDesk")
                                                                          , ConfigSettings.ReadConfigValue("SmtpClientPassword", "welcome@123"));
                SendEmailDelegate sd = new SendEmailDelegate(smtpClient.Send);
                AsyncCallback     cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(m, cb, sd);
                return(true);
            }
            catch (Exception ex)
            {
                this.LogError("Error sending the message", ex);
                return(false);
            }
        }
Example #17
0
        public static void Send(string sender, string reciver, string subject, string body, string host, int port, bool useSsl, string serverUsername, string serverPassword, bool Async)
        {
            try
            {
                MailMessage m = new MailMessage()
                {
                    Subject         = subject,
                    SubjectEncoding = Encoding.UTF8,
                    BodyEncoding    = Encoding.UTF8,
                    IsBodyHtml      = true,
                    Body            = body,
                    From            = new MailAddress(sender)
                };

                m.To.Clear();
                m.To.Add(reciver);

                SmtpClient client = new SmtpClient
                {
                    Host                  = host,
                    Port                  = port,
                    EnableSsl             = useSsl,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(serverUsername, serverPassword)
                };

                if (Async)
                {
                    var delg = new SendEmailDelegate(client.Send);
                    delg.BeginInvoke(m, new AsyncCallback(EmailManager.SendEmailCallback), delg);
                }
                else
                {
                    client.Send(m);
                }
            }
            catch (Exception exception)
            {
                Log.WriteError(MethodBase.GetCurrentMethod(), exception);
            }
        }
Example #18
0
        private static void SendEmailResponse(IAsyncResult ar)
        {
            SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);

            try
            {
                sd.EndInvoke(ar);

                var errorMessage = new ErrorMessage();
                errorMessage.Name       = "Sending mail successfully!";
                errorMessage.Function   = "Sending mail";
                errorMessage.CreateTime = DateTime.Now;
                new ErrorMessageDAO().Add(errorMessage);
            }
            catch (Exception ex)
            {
                var errorMessage = new ErrorMessage();
                errorMessage.Name       = ex.Message;
                errorMessage.Function   = "Sending mail";
                errorMessage.CreateTime = DateTime.Now;
                new ErrorMessageDAO().Add(errorMessage);
            }
        }
Example #19
0
        public async Task SendEmail(MailMessage m, Boolean Async)
        {
            SmtpClient smtp = null;

            smtp = new SmtpClient(_configuration["MailSettings:Server"])
            {
                UseDefaultCredentials = bool.Parse(_configuration["MailSettings:UseDefaultCredentials"]),
                Port        = int.Parse(_configuration["MailSettings:Port"]),
                EnableSsl   = bool.Parse(_configuration["MailSettings:EnableSsl"]),
                Credentials = new NetworkCredential(_configuration["MailSettings:UserName"], _configuration["MailSettings:Password"])
            };
            smtp = new SmtpClient();

            if (Async)
            {
                SendEmailDelegate sd = new SendEmailDelegate(smtp.SendMailAsync);
                AsyncCallback     cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(m, cb, sd);
            }
            else
            {
                await smtp.SendMailAsync(m);
            }
        }
Example #20
0
        /// <summary>
        /// Receive a new report and send it by email
        /// </summary>
        /// <param name="report">The report.</param>
        public void ReportPublished(ProblemReport report)
        {
            var method = new SendEmailDelegate(SendEmail);

            method.BeginInvoke(report, null, null);
        }
Example #21
0
    public static void SendAsyncEmail(MailAddress From, MailAddress[] To, string Subject, string Body, Attachment[] Attachments, MailAddress[] CC, MailAddress[] BCC)
    {
        try
        {
            MailMessage m = new MailMessage();
            m.From = From;

            //  Add To
            foreach (MailAddress a in To)
            {
                m.To.Add(a);
            }
            //  Add CC
            if (CC != null)
            {
                foreach (MailAddress a in CC)
                {
                    m.CC.Add(a);
                }
            }
            //  Add BCC
            if (BCC != null)
            {
                foreach (MailAddress a in BCC)
                {
                    m.Bcc.Add(a);
                }
            }
            m.Subject = Subject;
            m.Body = Body;

            if (Attachments != null)
            {
                foreach (Attachment a in Attachments)
                {
                    m.Attachments.Add(a);
                }
            }

            //  Send Message
            SmtpClient smtp = new SmtpClient();
            //  smtp.EnableSsl = true;
            SendEmailDelegate sd = new SendEmailDelegate(smtp.Send);
            AsyncCallback cb = new AsyncCallback(SendEmailResponse);
            sd.BeginInvoke(m, cb, sd);
        }
        catch (Exception ex)
        {
        }
    }
Example #22
0
        private static void SendEmailResponse(IAsyncResult ar)
        {
            SendEmailDelegate sd = (SendEmailDelegate)ar.AsyncState;

            sd.EndInvoke(ar);
        }
Example #23
0
        public static void SendEmailAttach(string to, string bcc, string subject, string body, HttpPostedFile attachment)
        {
            try
            {
                var smtpSec = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");

                // Initialize the mailmessage class
                var message = new MailMessage();
                message.From = new MailAddress(smtpSec.Network.UserName,
                                               ConfigurationManager.AppSettings["EmailDisplayName"]);
                // Set the recepient address of the mail message
                if (!string.IsNullOrEmpty(to))
                {
                    if (to.Contains(","))
                    {
                        var sto = to.Split(new[] { ',' });
                        for (var i = 0; i < sto.Length; i++)
                        {
                            if (sto[i] != null && sto[i] != string.Empty)
                            {
                                message.To.Add(new MailAddress(sto[i]));
                            }
                        }
                    }
                    else
                    {
                        message.To.Add(new MailAddress(to));
                    }
                }

                // Check if the bcc value is null or an empty string
                if (!string.IsNullOrEmpty(bcc))
                {
                    if (bcc.Contains(","))
                    {
                        var sbcc = bcc.Split(new char[] { ',' });
                        for (var i = 0; i < sbcc.Length; i++)
                        {
                            if (sbcc[i] != null && sbcc[i] != string.Empty)
                            {
                                message.Bcc.Add(new MailAddress(sbcc[i]));
                            }
                        }
                    }
                    else
                    {
                        // Set the Bcc address of the mail message
                        message.Bcc.Add(new MailAddress(bcc));
                    }
                }

                message.Subject = subject;
                // Set the body of the mail message
                message.Body = body;

                message.IsBodyHtml = true;

                // Set the priority of the mail message to normal
                message.Priority = MailPriority.Normal;
                if (attachment != null && attachment.ContentLength != 0)
                {
                    message.Attachments.Add(new Attachment(attachment.InputStream, attachment.FileName));
                }
                var encode = new UTF8Encoding();
                message.BodyEncoding = encode;

                /* Create SMTP Client and add credentials */
                var smtpClient = new SmtpClient(smtpSec.Network.Host)
                {
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(smtpSec.Network.UserName, smtpSec.Network.Password)
                };
                /* Email with Authentication */

                /* Send the message */
                //smtpClient.Send(message);
                var sd = new SendEmailDelegate(smtpClient.Send);
                var cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(message, cb, sd);
            }
            catch (Exception ex)
            {
                //Exceptions.Logger.Error(ex);
            }
        }
 private bool SendEmailAsync(string subject, string messageBody)
 {
     try
     {
         SendEmailDelegate dc = new SendEmailDelegate(this.SendEmail);
         AsyncCallback cb = new AsyncCallback(this.GetResultsOnCallback);
         IAsyncResult ar = dc.BeginInvoke(subject, messageBody, cb, null);
     }
     catch (Exception ex)
     {
         return false;
     }
     return true;
 }
Example #25
0
        public bool SendEmail(string to, string bcc, string cc, string subject, string body)
        {
            try
            {
                SmtpSection smtpSec = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
                // Initialize the mailmessage class
                MailMessage message = new MailMessage();
                message.From = new MailAddress(smtpSec.From, ConfigurationManager.AppSettings["EmailDisplayName"]);
                // Set the recepient address of the mail message
                if ((to != null) && (to != string.Empty))
                {
                    to = to.Replace(";", ",");
                    if (to.Contains(","))
                    {
                        string[] sto = to.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string s in sto)
                        {
                            if (Globals.ValidateEmail(s))
                            {
                                message.To.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (Globals.ValidateEmail(to))
                        {
                            message.To.Add(new MailAddress(to));
                        }
                    }
                }

                // Check if the bcc value is null or an empty string
                if ((bcc != null) && (bcc != string.Empty))
                {
                    bcc = bcc.Replace(";", ",");
                    if (bcc.Contains(","))
                    {
                        string[] sbcc = bcc.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string s in sbcc)
                        {
                            if (Globals.ValidateEmail(s))
                            {
                                message.Bcc.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (Globals.ValidateEmail(bcc))
                        {
                            message.Bcc.Add(new MailAddress(bcc));
                        }
                    }
                }
                // Check if the cc value is null or an empty value
                if ((cc != null) && (cc != string.Empty))
                {
                    cc = cc.Replace(";", ",");
                    if (cc.Contains(","))
                    {
                        string[] scc = cc.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string s in scc)
                        {
                            if (Globals.ValidateEmail(s))
                            {
                                message.CC.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (Globals.ValidateEmail(cc))
                        {
                            message.CC.Add(new MailAddress(cc));
                        }
                    }
                }

                message.Subject = subject;
                // Set the body of the mail message
                message.Body = body;

                message.IsBodyHtml = true;

                // Set the priority of the mail message to normal
                message.Priority = MailPriority.Normal;
                UTF8Encoding Encode = new UTF8Encoding();
                message.BodyEncoding = Encode;

                /* Create SMTP Client and add credentials */
                SmtpClient smtpClient = new SmtpClient(smtpSec.Network.Host, smtpSec.Network.Port);
                smtpClient.UseDefaultCredentials = false;
                /* Email with Authentication */
                smtpClient.Credentials = new NetworkCredential(smtpSec.Network.UserName, smtpSec.Network.Password);
                //smtpClient.EnableSsl = true;
                /* Send the message */
                //smtpClient.Send(message);



                SendEmailDelegate sd = new SendEmailDelegate(smtpClient.Send);
                AsyncCallback     cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(message, cb, sd);

                //System.Threading.Thread th = new Thread(() => SendMail(smtpClient, message));
                //th.IsBackground = true;
                //th.Start();
                // ts.
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #26
0
        public static bool SendEmailDirect(string to, string bcc, string cc, string subject, string body)
        {
            try
            {
                var smtpSec = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");

                // Initialize the mailmessage class
                var message = new MailMessage();
                message.From = new MailAddress(smtpSec.Network.UserName,
                                               ConfigurationManager.AppSettings["EmailDisplayName"]);
                // Set the recepient address of the mail message
                if (!string.IsNullOrEmpty(to))
                {
                    to = to.Replace(";", ",");
                    if (to.Contains(","))
                    {
                        var sto = to.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var s in sto)
                        {
                            if (HtmlHelper.ValidateEmail(s))
                            {
                                message.To.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (HtmlHelper.ValidateEmail(to))
                        {
                            message.To.Add(new MailAddress(to));
                        }
                    }
                }

                // Check if the bcc value is null or an empty string
                if (!string.IsNullOrEmpty(bcc))
                {
                    bcc = bcc.Replace(";", ",");
                    if (bcc.Contains(","))
                    {
                        var sbcc = bcc.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var s in sbcc)
                        {
                            if (HtmlHelper.ValidateEmail(s))
                            {
                                message.Bcc.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (HtmlHelper.ValidateEmail(bcc))
                        {
                            message.Bcc.Add(new MailAddress(bcc));
                        }
                    }
                }
                // Check if the cc value is null or an empty value
                if (!string.IsNullOrEmpty(cc))
                {
                    cc = cc.Replace(";", ",");
                    if (cc.Contains(","))
                    {
                        var scc = cc.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var s in scc)
                        {
                            if (HtmlHelper.ValidateEmail(s))
                            {
                                message.CC.Add(new MailAddress(s));
                            }
                        }
                    }
                    else
                    {
                        if (HtmlHelper.ValidateEmail(cc))
                        {
                            message.CC.Add(new MailAddress(cc));
                        }
                    }
                }

                message.Subject = subject;
                // Set the body of the mail message
                message.Body = body;

                message.IsBodyHtml = true;

                // Set the priority of the mail message to normal
                message.Priority = MailPriority.Normal;
                var encode = new UTF8Encoding();
                message.BodyEncoding = encode;

                /* Create SMTP Client and add credentials */
                var smtpClient = new SmtpClient(smtpSec.Network.Host)
                {
                    UseDefaultCredentials = false,
                    EnableSsl             = true, //Open SSL when GoogleMail, YahooMail
                    Credentials           = new NetworkCredential(smtpSec.Network.UserName, smtpSec.Network.Password)
                };
                /* Email with Authentication */

                /* Send the message */
                //smtpClient.Send(message);
                var sd = new SendEmailDelegate(smtpClient.Send);
                var cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(message, cb, sd);
                return(true);
            }
            catch (Exception ex)
            {
                //Exceptions.Logger.Error(ex);
                return(false);
            }
        }
Example #27
0
 public void SendEmailAsync()
 {
     var del = new SendEmailDelegate(this.SendEmail);
     var callBack = new AsyncCallback(this.GetResultsOnCallback);
     var ar = del.BeginInvoke(callBack, null);
 }
Example #28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var email = Request["email"];
        var name = Request["name"];
        var id = Request["id"];
        var username = Request["username"];
        var verified = Request["verified"];
        var Captcha = Request["Captcha"];
        var Email = Request["Email"];
        var Pwd = Request["Pwd"];
        var Ten = Request["Ten"];
        var Rem = Request["Rem"];
        var dic = Server.MapPath("~/lib/up/users/");
        Rem = !string.IsNullOrEmpty(Rem) ? "true" : "false";
        switch (subAct)
        {
            case "signupFb":
                #region Sigup
                if(!string.IsNullOrEmpty(id))
                {
                    var userFb = MemberDal.SelectByFbId(id);
                    if(string.IsNullOrEmpty(userFb.Username))
                    {
                        var userEmail = MemberDal.SelectByEmail(email);
                        var userUsername = MemberDal.SelectByUsername(username);
                        userFb.Username = username;
                        if (!string.IsNullOrEmpty(userUsername.Username))
                        {
                            userFb.Username = email;
                        }
                        if (!string.IsNullOrEmpty(userEmail.Username))
                        {
                            rendertext("2");
                        }
                        userFb.Ten = name;
                        userFb.CQ_ID = 1;
                        userFb.NgayTao = DateTime.Now;
                        userFb.XacNhan = true;
                        userFb.NgayXacNhan = DateTime.Now;
                        userFb.ChungThuc = false;
                        userFb.Email = email;
                        userFb.FbId = id;
                        userFb.RowId = Guid.NewGuid();
                        userFb.Active = true;
                        userFb = MemberDal.Insert(userFb);
                        var saveAvatar = new SaveAvatarDelegate(SaveAvatar);
                        saveAvatar.BeginInvoke(userFb.Id, id, dic, null, null);
                        MemberDal.UpdateVcard(DAL.con(), userFb.Username);
                        Security.Login(username, "true");
                        rendertext("1");
                    }
                    rendertext("0");
                }
                break;
                #endregion
            case "checkFbId":
                #region Check exsist username by FbId
                if (!string.IsNullOrEmpty(id))
                {
                    var userFb = MemberDal.SelectByFbId(id);
                    if (string.IsNullOrEmpty(userFb.Username))
                    {
                        rendertext("0");
                    }
                    Security.Login(userFb.Username, "true");
                    rendertext("1");
                }
                break;
                #endregion
            case "signup":
                #region Sigup
                if (!string.IsNullOrEmpty(Email))
                {
                    if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Ten) || string.IsNullOrEmpty(Pwd) || string.IsNullOrEmpty(Captcha))
                    {
                        rendertext("3");
                    }

                    if(Captcha.ToLower() != Session["capcha"].ToString().ToLower())
                    {
                        rendertext("0");
                    }

                    var user = MemberDal.SelectByEmail(Email);
                    if (!string.IsNullOrEmpty(user.Username))
                    {
                        rendertext("2");
                    }
                    user.Username = Email;
                    user.Ten = Ten;
                    user.Password = maHoa.EncryptString(Pwd, Email);
                    user.CQ_ID = 1;
                    user.NgayTao = DateTime.Now;
                    user.XacNhan = false;
                    user.ChungThuc = false;
                    user.Email = Email;
                    user.Active = true;
                    user.RowId = Guid.NewGuid();
                    user.DiaChi = CaptchaImage.GenerateRandomCode(CaptchaType.Numeric, 6);
                    user = MemberDal.Insert(user);
                    var obj = ObjDal.Insert(new Obj()
                    {
                        Id = Guid.NewGuid()
                        ,
                        Kieu = typeof(Member).FullName
                        ,
                        NgayTao = DateTime.Now
                        ,
                        RowId = user.RowId
                        ,
                        Url = user.Url
                        ,
                        Username = Security.Username
                        ,
                        Ten = user.Ten
                    });

                    MemberDal.UpdateVcard(DAL.con(), user.Username);

                    Security.Login(user.Username, Pwd, "true");

                    var dele = new SendEmailDelegate(SendMailSingle);
                    var emailTemp = Lib.GetResource(typeof(Class1).Assembly, "Xetui-email-welcome.html");
                    dele.BeginInvoke(user.Email, "Xetui.vn - Xac nhan tai khoan"
                                     , string.Format(emailTemp, user.Ten, user.Email, user.Id, user.DiaChi)
                                     , null, null);

                    rendertext("1");
                }
                rendertext("3");
                break;
                #endregion
            case "reSendActive":
                #region reSend Active
                if (Security.IsAuthenticated())
                {
                    var user = MemberDal.SelectAllByUserName(Security.Username);
                    user.DiaChi = CaptchaImage.GenerateRandomCode(CaptchaType.Numeric, 6);
                    user = MemberDal.Update(user);
                    var dele = new SendEmailDelegate(SendMailSingle);
                    var emailTemp = Lib.GetResource(typeof(Class1).Assembly, "Xetui-email-welcome.html");
                    dele.BeginInvoke(user.Email, "Xetui.vn - Xac nhan tai khoan"
                                     , string.Format(emailTemp, user.Ten, user.Email, user.Id, user.DiaChi)
                                     , null, null);
                    rendertext("1");
                }
                rendertext("0");
                break;
                #endregion
            case "recover-sendEmail":
                #region recover sendEmail
                if (!string.IsNullOrEmpty(Email))
                {
                    var user = MemberDal.SelectAllByUserName(Email);
                    if(user.Id==0)
                        rendertext("0");
                    if (!user.XacNhan)
                        rendertext("2");
                    user.DiaChi = CaptchaImage.GenerateRandomCode(CaptchaType.Numeric, 6);
                    user = MemberDal.Update(user);
                    var dele = new SendEmailDelegate(SendMailSingle);
                    var emailTemp = Lib.GetResource(typeof(Class1).Assembly, "Lay-lai-mat-khau.html");
                    dele.BeginInvoke(user.Email, "Xetui.vn - Lay lai mat khau"
                                     , string.Format(emailTemp, user.Ten, user.Email, user.Id, user.DiaChi)
                                     , null, null);
                    rendertext("1");
                }
                rendertext("0");
                break;
                #endregion
            case "recover-newPassword":
                #region recover newPassword
                if (!string.IsNullOrEmpty(id))
                {
                    var user = MemberDal.SelectById(Convert.ToInt32(id));
                    if (user.Id == 0)
                        rendertext("0");
                    if (!user.XacNhan)
                        rendertext("2");
                    user.DiaChi = string.Empty;
                    user.Password = maHoa.EncryptString(Pwd, user.Username);
                    user = MemberDal.Update(user);
                    Security.Login(user.Username, "true");
                    rendertext("1");
                }
                rendertext("0");
                break;
                #endregion
            case "login":
                #region Login
                if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Pwd))
                {
                    var ok = Security.Login(Email, Pwd, Rem);
                    if(ok)
                    {
                        var user = MemberDal.SelectAllByUserName(Email);
                        if(!user.Active)
                        {
                            Security.LogOut();
                            rendertext("2");
                        }
                        rendertext("1");
                    }
                    rendertext("0");
                }
                rendertext("0");
                break;
                #endregion
            case "logout":
                #region logout this system
                Security.LogOut();
                break;
                #endregion
        }
    }
Example #29
0
        public void SendEmail(System.Net.Mail.SmtpClient client, System.Net.Mail.MailMessage m)
        {
            try
            {
                SendEmailDelegate sd = new SendEmailDelegate(client.Send);

                AsyncCallback cb = new AsyncCallback(SendEmailResponse);
                sd.BeginInvoke(m, cb, sd);

                //client.Send(m);
            }
            catch (Exception ex)
            {
                logger.Error("----------- Error when send email to : " + m.To);
                logger.Error(ex.Message);
            }
        }
Example #30
0
 public bool SendEmailAsync(string toEmail, string toName)
 {
     try
     {
         SendEmailDelegate dc = new SendEmailDelegate(this.SendEmail);
         AsyncCallback cb = new AsyncCallback(this.GetResultsOnCallback);
         IAsyncResult ar = dc.BeginInvoke(toEmail, toName, cb, null);
     }
     catch (Exception ex)
     {
         return false;
     }
     return true;
 }