Exemplo n.º 1
0
        private bool AttemptToHandleCustomUrlScheme(Android.Webkit.WebView view, string url)
        {
            if (url.StartsWith("mailto"))
            {
                MailTo emailData = MailTo.Parse(url);

                var email = new Intent(Intent.ActionSendto);

                email.SetData(Uri.Parse("mailto:"));
                email.PutExtra(Intent.ExtraEmail, new[] { emailData.To });
                email.PutExtra(Intent.ExtraSubject, emailData.Subject);
                email.PutExtra(Intent.ExtraCc, emailData.Cc);
                email.PutExtra(Intent.ExtraText, emailData.Body);

                if (email.ResolveActivity(Forms.Context.PackageManager) != null)
                {
                    Forms.Context.StartActivity(email);
                }

                return(true);
            }

            if (url.StartsWith("http"))
            {
                var webPage = new Intent(Intent.ActionView, Uri.Parse(url));
                if (webPage.ResolveActivity(Forms.Context.PackageManager) != null)
                {
                    Forms.Context.StartActivity(webPage);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public static void Compose(string url)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                return;
            }

            MailTo mailTo = MailTo.ParseUrl(url);

            var mailComposer = new MFMailComposeViewController();

            mailComposer.MailComposeDelegate = new MailComposeDelegate();
            mailComposer.SetToRecipients(mailTo.EmailTo.ToArray());
            mailComposer.SetSubject(mailTo.EmailSubject);
            mailComposer.SetMessageBody(mailTo.EmailBody, true);

            foreach (var attachment in mailTo.EmailAttachments)
            {
                string path = attachment.Filename;
                if (!File.Exists(path))
                {
                    path = Path.Combine(TouchFactory.Instance.DataPath, attachment.Filename);
                }

                NSData data = NSData.FromFile(path);
                if (data != null)
                {
                    mailComposer.AddAttachmentData(data, attachment.MimeType, attachment.Filename);
                }
            }

            ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, mailComposer, true);
        }
Exemplo n.º 3
0
        public void SetMailTo(string emails)
        {
            var temp = emails.Split(';');

            MailTo.AddRange(temp);
            MailTo.Remove(string.Empty);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fill method for populating an entire collection of MailToCollection
        /// </summary>
        public virtual void Fill(MailToCollection mailToCollection)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());


            try
            {
                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectMailToCollection");


                    // Send the collection and data to the object factory
                    CreateObjectsFromData(mailToCollection, datareader);


                    // close the connection
                    cnn.Close();
                }


                // nullify the connection
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(MailToCollection mailtocollection, System.Data.DataSet data)
        {
            // Do nothing if we have nothing
            if (data == null || data.Tables.Count == 0 || data.Tables[0].Rows.Count == 0)
            {
                return;
            }


            // Create a local variable for the new instance.
            MailTo newobj = null;

            // Create a local variable for the data row instance.
            System.Data.DataRow dr = null;


            // Iterate through the table rows
            for (int i = 0; i < data.Tables[0].Rows.Count; i++)
            {
                // Get a reference to the data row
                dr = data.Tables[0].Rows[i];
                // Create a new object instance
                newobj = System.Activator.CreateInstance(mailtocollection.ContainsType[0]) as MailTo;
                // Let the instance set its own members
                newobj.SetMembers(ref dr);
                // Add the new object to the collection instance
                mailtocollection.Add(newobj);
            }
        }
        public ActionResult SendMail(Mail mail)
        {
            bool chkSendMail = new MailTo().SendMail(mail);

            if (chkSendMail)
            {
                return(Content("true", "text/html"));
            }
            else
            {
                return(Content("false", "text/html"));
            }
        }
Exemplo n.º 7
0
        public string SetMailTo(string emails)
        {
            var temp      = emails.Split(';');
            var validator = new MailValidator("Adresaci są błędni");

            if (!validator.IsValid(temp))
            {
                return(validator.ErrorMesage);
            }
            MailTo.AddRange(temp);
            MailTo.Remove(string.Empty);
            return(string.Empty);
        }
Exemplo n.º 8
0
 private void SendEmail(string message)
 {
     if (DateTime.Now.ToString("yyyyMMddHH") != date)
     {
         date = DateTime.Now.ToString("yyyyMMddHH");
         MailMessage mailMessage = new MailMessage()
         {
             From       = new MailAddress(MailSender),
             Body       = message,
             Subject    = Subject,
             IsBodyHtml = false
         };
         Array.ForEach(MailTo.ToArray(), t => mailMessage.To.Add(t));
         SmtpClient.Send(mailMessage);
     }
 }
Exemplo n.º 9
0
        public void Add(MailDto mail)
        {
            //todo: fill another properties
            var mailTo = new MailTo
            {
                ToMailAddress = mail.ToEmailAddress,
                Message       = mail.Message,
                Subject       = mail.Subject,
                MailFrom      = new MailFrom
                {
                    SenderMailAddress = mail.SenderEmailAddress,
                    SenderPassword    = mail.SenderPassword
                }
            };

            _mailRepository.Add(mailTo);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deletes the object.
        /// </summary>
        public virtual void Delete(MailTo deleteObject)
        {
            // create a new instance of the connection
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;


            try
            {
                // discover the parameters
                sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_DeleteMailTo");


                // Store the parameter for the BorrowerId attribute.
                sqlparams["@borrowerId"].Value = deleteObject.BorrowerId;


                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // Execute the stored proc to perform the delete on the instance.
                    SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_DeleteMailTo", sqlparams);


                    // close the connection after usage
                    cnn.Close();
                }


                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }


            // nullify the reference
            deleteObject = null;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fill method for populating a collection by BORROWER
        /// </summary>
        public void FillByBorrower(MailToCollection mailToCollection, System.Int64 id)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());


            try
            {
                // discover the sql parameters
                SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_SelectMailToCollectionByBorrower");


                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // set the parameters
                    sqlparams["@borrowerId"].Value = id;


                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectMailToCollectionByBorrower", sqlparams);


                    // Send the collection and data to the object factory.
                    CreateObjectsFromData(mailToCollection, datareader);


                    // close the connection
                    cnn.Close();
                }


                // nullify the connection
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Fills a single instance with data based on its primary key values.
        /// </summary>
        public virtual void Fill(MailTo mailto, System.Int64 borrowerId)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());

            try
            {
                // discover the sql parameters
                SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_SelectMailTo");


                using (cnn)
                {
                    // open the connection
                    cnn.Open();


                    // set the parameters
                    sqlparams["@borrowerId"].Value = borrowerId;


                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectMailTo", sqlparams);


                    if (datareader.Read())
                    {
                        mailto.SetMembers(ref datareader);
                    }


                    cnn.Close();                     // close the connection
                }


                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 13
0
        private void SetMailTo(string emails)
        {
            var           temp       = emails.Split(';');
            var           validation = new EmailAddressAttribute();
            StringBuilder valid      = new StringBuilder();

            foreach (var s in temp)
            {
                if (!validation.IsValid(s))
                {
                    valid.Append($"{s} ");
                }
            }
            if (!string.IsNullOrEmpty(valid.ToString()))
            {
                throw new IncorrectRecipientException($"Incorrect recipient address for line: {valid}");
            }
            MailTo.AddRange(temp);
            MailTo.Remove(string.Empty);
        }
Exemplo n.º 14
0
        public ActionResult Register(RegisterModel rModel)
        {
            if (ModelState.IsValid)
            {
                var user = _readOnlyRepository.FirstOrDefault <AccountLogin>(x => x.Email == rModel.Email);
                if (user != null)
                {
                    //check
                    MessageBox.Show("User Exists.");
                }
                else
                {
                    var registeredAccount = new AccountLogin(rModel.Email, rModel.Name, (new Hasher()).Encrypt(rModel.Password), "user");

                    _writeOnlyRepository.Create(registeredAccount);
                    MailTo.SendSimpleMessage(rModel.Email, rModel.Name, "Gracias por Registrarse");
                } ModelState.AddModelError("", "Something went wrong with your credentials.");
            }

            return(View(rModel));
        }
Exemplo n.º 15
0
        /// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(MailToCollection mailtocollection, System.Data.SqlClient.SqlDataReader data)
        {
            // Do nothing if we have nothing
            if (data == null)
            {
                return;
            }


            // Create a local variable for the new instance.
            MailTo newobj = null;

            // Iterate through the data reader
            while (data.Read())
            {
                // Create a new object instance
                newobj = System.Activator.CreateInstance(mailtocollection.ContainsType[0]) as MailTo;
                // Let the instance set its own members
                newobj.SetMembers(ref data);
                // Add the new object to the collection instance
                mailtocollection.Add(newobj);
            }
        }
Exemplo n.º 16
0
        public string SendMailData(string Subject, string Message, string Sender, string Receiver, string MailCC = "", string MailBCC = "", string[] Filename = null)
        {
            SmtpClient  SMTPMail = null;
            MailMessage objMail  = null;
            MailAddress CcMail   = null;
            MailAddress Tomail   = null;
            MailAddress Frommail = null;

            string MailFrom = "";
            string MailTo   = "";
            string ErrMsg   = "";

            string[]    OneMail;
            string[]    OnemailTo;
            MailAddress BCcmail = null;

            string[] OneBccmail;
            int      i;
            string   TestMsg = "";
            string   FN      = "";
            string   FNlist  = "";

            try
            {
                if (Project.MailMode == "0")
                {
                    ErrMsg = "Mail Mode is closed status.";
                }
                else
                {
                    if (Project.MailMode == "1" || Project.MailMode == "3")
                    {
                        MailFrom = Sender == "" ? Project.SenderMail : Sender;
                        if (Project.TestMail != "")
                        {
                            TestMsg += " To : " + Receiver + "<br/>";
                            if (MailCC != "")
                            {
                                TestMsg += " Cc : " + MailCC + " <br/>";
                            }
                            if (MailBCC != "")
                            {
                                TestMsg += " Bcc : " + MailBCC + " <br/>";
                            }
                            Message = "This is for test system :  <br/>" + TestMsg + "<br/>" + Message;
                            Subject = "[TEST MAIL] " + Subject;
                            MailTo  = Project.TestMail;
                            MailCC  = "";
                            MailBCC = "";
                        }
                        else
                        {
                            MailTo = Receiver;
                        }


                        objMail = new MailMessage();
                        if (Project.SenderFrom != "")
                        {
                            Frommail = new MailAddress(MailFrom, Project.SenderFrom);
                        }
                        else
                        {
                            Frommail = new MailAddress(MailFrom);
                        }
                        objMail.From            = Frommail;
                        objMail.Subject         = Subject;
                        objMail.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                        objMail.Body            = Message;
                        objMail.IsBodyHtml      = true;
                        if (MailTo != "")
                        {
                            OnemailTo = MailTo.Split(';');
                            for (i = 0; i < OnemailTo.Length; i++)
                            {
                                try
                                {
                                    Tomail = new MailAddress(OnemailTo[i]);
                                    objMail.To.Add(Tomail);
                                }
                                catch { }
                            }
                        }

                        objMail.IsBodyHtml = true;
                        SMTPMail           = new SmtpClient();
                        SMTPMail.Host      = Project.smtpHost;
                        SMTPMail.EnableSsl = true;


                        if (Project.smtpPort != "")
                        {
                            SMTPMail.Port = Utilities.ToInt(Project.smtpPort);
                        }

                        if (Project.smtpUser != "")
                        {
                            SMTPMail.Credentials = new System.Net.NetworkCredential(Project.smtpUser, Project.smtpPassword);
                        }

                        SMTPMail.Send(objMail);
                        ErrMsg = "";
                    }
                }
            }
            catch (Exception ex)
            {
                ErrMsg = ex.Message;
            }

            return(ErrMsg);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Persists the object.
        /// </summary>
        public virtual void Persist(MailTo persistObject, SqlTransaction sqlTrans)
        {
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;
            // Create a local variable for the connection
            SqlConnection cnn = null;

            // Use the parameter overload or create a new instance
            if (sqlTrans == null)
                cnn = new SqlConnection(MailTo.GetConnectionString());

            try
            {
                // discover the parameters
                if (persistObject.Persisted)
                    sqlparams =  SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_UpdateMailTo");
                else
                    sqlparams =  SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_CreateMailTo");

                // Store the parameter for the StreetAddress attribute.
                if (!persistObject.StreetAddressIsNull)
                    sqlparams["@streetAddress"].Value = persistObject.StreetAddress;
                // Store the parameter for the StreetAddress2 attribute.
                if (!persistObject.StreetAddress2IsNull)
                    sqlparams["@streetAddress2"].Value = persistObject.StreetAddress2;
                // Store the parameter for the City attribute.
                if (!persistObject.CityIsNull)
                    sqlparams["@city"].Value = persistObject.City;
                // Store the parameter for the State attribute.
                if (!persistObject.StateIsNull)
                    sqlparams["@state"].Value = persistObject.State;
                // Store the parameter for the PostalCode attribute.
                if (!persistObject.PostalCodeIsNull)
                    sqlparams["@postalCode"].Value = persistObject.PostalCode;
                // Store the parameter for the Country attribute.
                if (!persistObject.CountryIsNull)
                    sqlparams["@country"].Value = persistObject.Country;
                // Store the parameter for the BorrowerId attribute.
                sqlparams["@borrowerId"].Value = persistObject.BorrowerId;
                if (!persistObject.Persisted)
                {
                    // store the create only (historical fixed) values
                }
                else
                {
                    // store the update only (historical changeable) values
                }

                if (sqlTrans == null)
                {
                    // Process using the isolated connection
                    using (cnn)
                    {
                        // open the connection
                        cnn.Open();

                        if (!persistObject.Persisted)
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_CreateMailTo", sqlparams);
                        }
                        else
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_UpdateMailTo", sqlparams);
                        }

                        // close the connection after usage
                        cnn.Close();
                    }

                    // nullify the connection var
                    cnn = null;
                }
                else
                {
                    // Process using the shared transaction
                    if (!persistObject.Persisted)
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_CreateMailTo", sqlparams);
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_UpdateMailTo", sqlparams);
                    }
                }
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Persists the object.
 /// </summary>
 public virtual void Persist(MailTo persistObject)
 {
     // Make a call to the overloaded method with a null transaction
     Persist(persistObject, null);
 }
Exemplo n.º 19
0
 /// <summary>
 /// MessageSend
 /// </summary>
 /// <param name="emailTo">Email to send email</param>
 /// <param name="subject">Email subject</param>
 /// <param name="body">Email body</param>
 public MessageSend(string emailTo, string subject, string body)
 {
     MailTo.Add(emailTo);
     Subject = subject;
     Body    = body;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Persists the object.
 /// </summary>
 public virtual void Persist(MailTo persistObject)
 {
     // Make a call to the overloaded method with a null transaction
     Persist(persistObject, null);
 }
Exemplo n.º 21
0
        void WBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            //Console.WriteLine("ResultBrowser WBrowserDocumentNavigating :" + e.Url);
            if (e.Url.AbsoluteUri == "about:blank")
            {
                return;
            }
            if ((e.Url.Host == "127.0.0.1" || e.Url.Host == WebUI.ResultsWebServer.Uri.Host) && e.Url.Port == WebUI.ResultsWebServer.Port)
            {
                return;
            }
            if (e.Url.AbsoluteUri.StartsWith(Constants.StatsPageUrl))
            {
                return;
            }
            if (e.Url.AbsoluteUri.StartsWith(Constants.ChangeLogPageUrlBase))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://pagead2.googlesyndication.com/pagead/ads?"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://ads.adbrite.com/adserver/display_iab_ads.php"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://syndication.exoclick.com/ads-iframe-display.php"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://ad2.adecn.com/here.spot"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://eb.adbureau.net/hserver"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://ad.iconadserver.com/st"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://ads.us.e-planning.net"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.StartsWith("http://b1.adbrite.com/iads"))
            {
                return;
            }



            if (e.Url.AbsoluteUri.StartsWith("javascript:"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.Contains("ieframe.dll"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.Contains("shdoclc.dll"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.Contains("addthis.com"))
            {
                return;
            }

            if (e.Url.AbsoluteUri.Contains("mailto:[email protected]"))
            {
                MailTo.Send(ApplicationInfo.SupportEmail,
                            LangPack.TranslateString("Feedback for :") + " " + ApplicationInfo.ProductName + " " + ApplicationInfo.ProductVersion,
                            LangPack.TranslateString("<< Enter your feedback or bug report here (English, Ukrainian, Russian). >>"));
                return;
            }


            HtmlHelper.OpenUrl(e.Url);
            e.Cancel = true;
        }
Exemplo n.º 22
0
 private static void SendUsingMailTo(Email.Email email)
 {
     MailTo.SendMail(email);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Persists the object.
        /// </summary>
        public virtual void Persist(MailTo persistObject, SqlTransaction sqlTrans)
        {
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;
            // Create a local variable for the connection
            SqlConnection cnn = null;


            // Use the parameter overload or create a new instance
            if (sqlTrans == null)
            {
                cnn = new SqlConnection(MailTo.GetConnectionString());
            }


            try
            {
                // discover the parameters
                if (persistObject.Persisted)
                {
                    sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_UpdateMailTo");
                }
                else
                {
                    sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_CreateMailTo");
                }


                // Store the parameter for the StreetAddress attribute.
                if (!persistObject.StreetAddressIsNull)
                {
                    sqlparams["@streetAddress"].Value = persistObject.StreetAddress;
                }
                // Store the parameter for the StreetAddress2 attribute.
                if (!persistObject.StreetAddress2IsNull)
                {
                    sqlparams["@streetAddress2"].Value = persistObject.StreetAddress2;
                }
                // Store the parameter for the City attribute.
                if (!persistObject.CityIsNull)
                {
                    sqlparams["@city"].Value = persistObject.City;
                }
                // Store the parameter for the State attribute.
                if (!persistObject.StateIsNull)
                {
                    sqlparams["@state"].Value = persistObject.State;
                }
                // Store the parameter for the PostalCode attribute.
                if (!persistObject.PostalCodeIsNull)
                {
                    sqlparams["@postalCode"].Value = persistObject.PostalCode;
                }
                // Store the parameter for the Country attribute.
                if (!persistObject.CountryIsNull)
                {
                    sqlparams["@country"].Value = persistObject.Country;
                }
                // Store the parameter for the BorrowerId attribute.
                sqlparams["@borrowerId"].Value = persistObject.BorrowerId;
                if (!persistObject.Persisted)
                {
                    // store the create only (historical fixed) values
                }
                else
                {
                    // store the update only (historical changeable) values
                }


                if (sqlTrans == null)
                {
                    // Process using the isolated connection
                    using (cnn)
                    {
                        // open the connection
                        cnn.Open();


                        if (!persistObject.Persisted)
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_CreateMailTo", sqlparams);
                        }
                        else
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_UpdateMailTo", sqlparams);
                        }


                        // close the connection after usage
                        cnn.Close();
                    }


                    // nullify the connection var
                    cnn = null;
                }
                else
                {
                    // Process using the shared transaction
                    if (!persistObject.Persisted)
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_CreateMailTo", sqlparams);
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_UpdateMailTo", sqlparams);
                    }
                }
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Deletes the object.
        /// </summary>
        public virtual void Delete(MailTo deleteObject)
        {
            // create a new instance of the connection
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;

            try
            {
                // discover the parameters
                sqlparams =  SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_DeleteMailTo");

                // Store the parameter for the BorrowerId attribute.
                sqlparams["@borrowerId"].Value = deleteObject.BorrowerId;

                using (cnn)
                {
                    // open the connection
                    cnn.Open();

                    // Execute the stored proc to perform the delete on the instance.
                    SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_DeleteMailTo", sqlparams);

                    // close the connection after usage
                    cnn.Close();
                }

                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }

            // nullify the reference
            deleteObject = null;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Fills a single instance with data based on its primary key values.
        /// </summary>
        public virtual void Fill(MailTo mailto, System.Int64 borrowerId)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(MailTo.GetConnectionString());
            try
            {
                // discover the sql parameters
                SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(MailTo.GetConnectionString(), "gsp_SelectMailTo");

                using (cnn)
                {
                    // open the connection
                    cnn.Open();

                    // set the parameters
                    sqlparams["@borrowerId"].Value = borrowerId;

                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectMailTo", sqlparams);

                    if (datareader.Read())
                        mailto.SetMembers(ref datareader);

                    cnn.Close(); // close the connection
                }

                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
Exemplo n.º 26
0
        /// <summary>寄發郵件,發送者、對象與伺服器設定直接來自 App.Config 或 LogManager 的靜態屬性(Static Properties)。</summary>
        /// <param name="subject">信件主旨</param>
        /// <param name="content">信件內容</param>
        /// <param name="throwError">錯誤時,是否直接往外丟出錯誤。</param>
        /// <param name="attachments">附件檔案。</param>
        public static void SendMail(string subject, string content, bool throwError, params string[] attachments)
        {
            NameValueCollection nvc = ConfigurationManager.AppSettings;
            string mailServer       = string.IsNullOrEmpty(MailServer) ? nvc["MailServer"] : MailServer;
            string mailSubject      = string.IsNullOrEmpty(DefSubject) ? nvc["MailSubject"] : DefSubject;
            int    mailPort         = 25;

            string[] mailTo = new string[] { };
            if (!string.IsNullOrEmpty(MailTo))
            {
                mailTo = MailTo.Split(';');
            }
            else if (!string.IsNullOrEmpty(nvc["MailTo"]))
            {
                mailTo = nvc["MailTo"].Split(';');
            }
            string mailFrom = string.IsNullOrEmpty(MailFrom) ? nvc["MailFrom"] : MailFrom;

            if (string.IsNullOrEmpty(mailServer) || mailTo.Length == 0 || string.IsNullOrEmpty(mailFrom))
            {
                return;
            }
            string userName = string.IsNullOrEmpty(FromUser) ? nvc["FromUser"] : FromUser;
            string pwd      = string.IsNullOrEmpty(FromPWD) ? nvc["FromPWD"] : FromPWD;

            if (MailEncoding == null)
            {
                MailEncoding = Encoding.UTF8;
            }
            try
            {
                MailMessage mail = new MailMessage();                   // MailMessage(寄信者, 收信者)
                mail.From = new MailAddress(mailFrom);
                foreach (string s in mailTo)
                {
                    mail.To.Add(s);
                }
                mail.IsBodyHtml   = UseHTML;
                mail.BodyEncoding = MailEncoding;                                          // E-mail編碼
                mail.Subject      = string.IsNullOrEmpty(subject) ? mailSubject : subject; // E-mail主旨
                mail.Body         = content;                                               // E-mail內容
                foreach (string f in attachments)
                {
                    mail.Attachments.Add(new Attachment(f));
                }
                if (mailServer.IndexOf(':') != -1)
                {
                    mailPort   = Convert.ToInt32(mailServer.Split(':')[1]);
                    mailServer = mailServer.Split(':')[0];
                }
                SmtpClient smtpClient = new SmtpClient(mailServer, mailPort);                   // 設定E-mail Server和port
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials           = new System.Net.NetworkCredential(userName, pwd);
                smtpClient.Send(mail);
            }
            catch (Exception ex)
            {
                if (throwError)
                {
                    throw;
                }
                LogException("Mail", ex, false);
            }
        }