Exemple #1
0
        }       //	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);
        }
        }       //	sendNoGuaranteeMail

        /// <summary>
        /// Deliver Asset
        /// </summary>
        /// <param name="A_Asset_ID">asset</param>
        /// <returns>message - delivery errors start with **</returns>
        private String DeliverIt(int A_Asset_ID)
        {
            log.Fine("A_Asset_ID=" + A_Asset_ID);
            long start = CommonFunctions.CurrentTimeMillis();
            //
            MAsset asset = new MAsset(GetCtx(), A_Asset_ID, Get_Trx());

            if (asset.GetAD_User_ID() == 0)
            {
                return("** No Asset User");
            }
            VAdvantage.Model.MUser user = new VAdvantage.Model.MUser(GetCtx(), asset.GetAD_User_ID(), Get_Trx());
            if (user.GetEMail() == null || user.GetEMail().Length == 0)
            {
                return("** No Asset User Email");
            }
            if (asset.GetProductR_MailText_ID() == 0)
            {
                return("** Product Mail Text");
            }
            if (_MailText == null || _MailText.GetR_MailText_ID() != asset.GetProductR_MailText_ID())
            {
                _MailText = new VAdvantage.Model.MMailText(GetCtx(), asset.GetProductR_MailText_ID(), Get_Trx());
            }
            if (_MailText.GetMailHeader() == null || _MailText.GetMailHeader().Length == 0)
            {
                return("** No Subject");
            }

            //	Create Mail
            EMail email = _client.CreateEMail(user.GetEMail(), user.GetName(), null, null);

            if (email == null || !email.IsValid())
            {
                asset.SetHelp(asset.GetHelp() + " - Invalid EMail");
                asset.SetIsActive(false);
                return("** Invalid EMail: " + user.GetEMail() + " - " + email);
            }
            if (_client.IsSmtpAuthorization())
            {
                email.CreateAuthenticator(_client.GetRequestUser(), _client.GetRequestUserPW());
            }
            _MailText.SetUser(user);
            _MailText.SetPO(asset);
            String message = _MailText.GetMailText(true);

            if (_MailText.IsHtml() || _AttachAsset)
            {
                email.SetMessageHTML(_MailText.GetMailHeader(), message);
            }
            else
            {
                email.SetSubject(_MailText.GetMailHeader());
                email.SetMessageText(message);
            }
            if (_AttachAsset)
            {
                MProductDownload[] pdls = asset.GetProductDownloads();
                if (pdls != null)
                {
                    foreach (MProductDownload element in pdls)
                    {
                        //URL url = element.getDownloadURL(m_client.getDocumentDir());
                        Url url = element.GetDownloadURL(_client.GetDocumentDir());
                        if (url != null)
                        {
                            email.AddAttachment(url.Value);
                        }
                    }
                }
                else
                {
                    log.Warning("No DowloadURL for A_Asset_ID=" + A_Asset_ID);
                }
            }
            String msg = email.Send();

            new MUserMail(_MailText, asset.GetAD_User_ID(), email).Save();
            if (!EMail.SENT_OK.Equals(msg))
            {
                return("** Not delivered: " + user.GetEMail() + " - " + msg);
            }

            MAssetDelivery ad = asset.ConfirmDelivery(email, user.GetAD_User_ID());

            ad.Save();
            asset.Save();
            //
            log.Fine((CommonFunctions.CurrentTimeMillis() - start) + " ms");
            //	success
            return(user.GetEMail() + " - " + asset.GetProductVersionNo());
        }