コード例 #1
0
ファイル: MStore.cs プロジェクト: vuongthai91/ERP-CMR-DMS
        }       //	beforeSave

        /// <summary>
        ///	Create EMail from Request User
        /// </summary>
        /// <param name="toEMail">recipient</param>
        /// <param name="toName">tomail</param>
        /// <param name="subject">subject</param>
        /// <param name="message">message</param>
        /// <returns>Email</returns>
        public EMail CreateEMail(String toEMail, String toName,
                                 String subject, String message)
        {
            if (toEMail == null || toEMail.Length == 0)
            {
                _log.Warning("No To");
                return(null);
            }

            //
            EMail   email  = null;
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            if (client.IsServerEMail() && Ini.IsClient())
            {
                //MessageBox.Show("Get Connection Problem");
                //Server server = CConnection.get().getServer();

                try
                {
                    //if (server != null)
                    if (!DataBase.DB.IsConnected())
                    {
                        email = CreateEMail(toEMail, toName, subject, message);
                    }

                    //{	//	See ServerBean
                    //    email = server.CreateEMail(GetCtx(), GetAD_Client_ID(),
                    //        toEMail, toName, subject, message);

                    //}
                    else
                    {
                        log.Log(Level.WARNING, "No AppsServer");
                    }
                }
                catch (Exception ex)
                {
                    log.Log(Level.SEVERE, GetName() + " - AppsServer error", ex);
                }
            }
            String from = GetWStoreEMail();

            if (from == null || from.Length == 0)
            {
                from = client.GetRequestEMail();
            }
            if (email == null)
            {
                email = new EMail(client,
                                  from, client.GetName(), toEMail, toName,
                                  subject, message);
            }
            //	Authorizetion
            if (client.IsSmtpAuthorization())
            {
                if (GetWStoreEMail() != null && GetWStoreUser() != null && GetWStoreUserPW() != null)
                {
                    email.CreateAuthenticator(GetWStoreUser(), GetWStoreUserPW());
                }
                else
                {
                    email.CreateAuthenticator(client.GetRequestUser(), client.GetRequestUserPW());
                }
            }
            //	Bcc
            email.AddBcc(from);
            //
            return(email);
        }